回答編集履歴

1

コードをリファクタリングした

2020/05/23 09:24

投稿

yu-imu
yu-imu

スコア35

test CHANGED
@@ -32,13 +32,7 @@
32
32
 
33
33
  #画像関連
34
34
 
35
- dev_server = env["HTTP_HOST"].gsub(":3000", ":3035")
36
-
37
- env["HTTP_HOST"] = dev_server
35
+ change_http_host(env)
38
-
39
- env["HTTP_X_FORWARDED_HOST"] = dev_server
40
-
41
- env["HTTP_X_FORWARDED_SERVER"] = dev_server
42
36
 
43
37
  env["PATH_INFO"] = "/images/" + env["PATH_INFO"].split("/").last
44
38
 
@@ -48,13 +42,7 @@
48
42
 
49
43
  #通常のReactコード
50
44
 
51
- dev_server = env["HTTP_HOST"].gsub(":3000", ":3035")
52
-
53
- env["HTTP_HOST"] = dev_server
45
+ change_http_host(env)
54
-
55
- env["HTTP_X_FORWARDED_HOST"] = dev_server
56
-
57
- env["HTTP_X_FORWARDED_SERVER"] = dev_server
58
46
 
59
47
  super
60
48
 
@@ -62,13 +50,7 @@
62
50
 
63
51
  #lazy loadしているReactコード
64
52
 
65
- dev_server = env["HTTP_HOST"].gsub(":3000", ":3035")
66
-
67
- env["HTTP_HOST"] = dev_server
53
+ change_http_host(env)
68
-
69
- env["HTTP_X_FORWARDED_HOST"] = dev_server
70
-
71
- env["HTTP_X_FORWARDED_SERVER"] = dev_server
72
54
 
73
55
  env["PATH_INFO"] = "/packs/" + env["PATH_INFO"].split("/").last
74
56
 
@@ -82,6 +64,24 @@
82
64
 
83
65
  end
84
66
 
67
+
68
+
69
+ private
70
+
71
+
72
+
73
+ def change_http_host(env)
74
+
75
+ dev_server = env["HTTP_HOST"].gsub(":3000", ":3035")
76
+
77
+ env["HTTP_HOST"] = dev_server
78
+
79
+ env["HTTP_X_FORWARDED_HOST"] = dev_server
80
+
81
+ env["HTTP_X_FORWARDED_SERVER"] = dev_server
82
+
83
+ end
84
+
85
85
  end
86
86
 
87
87
  ```