質問編集履歴

7

説明を修正

2020/10/14 13:58

投稿

Linkey
Linkey

スコア77

test CHANGED
File without changes
test CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  STS(Spring Tool Suite)でWebアプリケーション実装
16
16
 
17
- DockerでUbuntuを起動してionicからリクエストを受け付ける(8080ポートを開放)
17
+ DockerでUbuntuを起動してionicからリクエストを受け付ける
18
18
 
19
19
 
20
20
 

6

実装の修正

2020/10/14 13:58

投稿

Linkey
Linkey

スコア77

test CHANGED
File without changes
test CHANGED
@@ -202,21 +202,43 @@
202
202
 
203
203
  // URLアクセス設定
204
204
 
205
- http.authorizeRequests().mvcMatchers("/getToken").permitAll();
205
+ http.authorizeRequests().mvcMatchers("/getToken").permitAll()
206
+
207
+ .and().cors().configurationSource(this.corsConfigurationSource());
206
208
 
207
209
  }
208
210
 
209
211
  @Bean
210
212
 
211
- UrlBasedCorsConfigurationSource corsConfigurationSource() {
213
+ public org.springframework.web.cors.CorsConfigurationSource corsConfigurationSource() {
212
214
 
213
215
  CorsConfiguration configuration = new CorsConfiguration();
214
216
 
217
+ configuration.setAllowCredentials(true);
218
+
215
- configuration.setAllowedOrigins(Arrays.asList("http://localhost:8100"));
219
+ configuration.setAllowedOrigins(Arrays.asList("http-nio-XXX.XXX.X.X-8080", "http-nio-XXX.XXX.X.X-8100"));
220
+
216
-
221
+ configuration.setAllowedHeaders(Arrays.asList(
222
+
223
+ "Access-Control-Allow-Headers",
224
+
225
+ "Access-Control-Allow-Origin",
226
+
227
+ "Access-Control-Request-Method",
228
+
229
+ "Access-Control-Request-Headers",
230
+
231
+ "Cache-Control",
232
+
233
+ "Content-Type",
234
+
235
+ "Accept-Language"));
236
+
217
- configuration.setAllowedMethods(Arrays.asList("GET","POST"));
237
+ configuration.setAllowedMethods(Arrays.asList("GET", "POST"));
218
-
238
+
239
+
240
+
219
- UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
241
+ org.springframework.web.cors.UrlBasedCorsConfigurationSource source = new org.springframework.web.cors.UrlBasedCorsConfigurationSource();
220
242
 
221
243
  source.registerCorsConfiguration("/**", configuration);
222
244
 
@@ -224,6 +246,8 @@
224
246
 
225
247
  }
226
248
 
249
+
250
+
227
251
  }
228
252
 
229
253
  ```

5

説明を修正

2020/10/14 13:57

投稿

Linkey
Linkey

スコア77

test CHANGED
File without changes
test CHANGED
@@ -104,6 +104,18 @@
104
104
 
105
105
  tty: true
106
106
 
107
+ ports:
108
+
109
+ - "127.0.0.1:8100:8100"
110
+
111
+ - "127.0.0.1:8080:8080"
112
+
113
+ expose:
114
+
115
+ - "8100"
116
+
117
+ - "8080"
118
+
107
119
 
108
120
 
109
121
  # MySQL

4

説明を編集

2020/10/14 13:53

投稿

Linkey
Linkey

スコア77

test CHANGED
File without changes
test CHANGED
@@ -84,6 +84,72 @@
84
84
 
85
85
  ```
86
86
 
87
+ docker-compose.yml
88
+
89
+ ```yaml
90
+
91
+ version: '3'
92
+
93
+
94
+
95
+ services:
96
+
97
+ #ubuntu
98
+
99
+ app:
100
+
101
+ image: ubuntu
102
+
103
+ command: /bin/bash
104
+
105
+ tty: true
106
+
107
+
108
+
109
+ # MySQL
110
+
111
+ db:
112
+
113
+ image: mysql:5.7
114
+
115
+ container_name: mysql_host
116
+
117
+ environment:
118
+
119
+ MYSQL_ROOT_PASSWORD: password
120
+
121
+ MYSQL_DATABASE: sample_db
122
+
123
+ MYSQL_USER: admin
124
+
125
+ MYSQL_PASSWORD: password
126
+
127
+ TZ: 'Asia/Tokyo'
128
+
129
+ command: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci
130
+
131
+ volumes:
132
+
133
+ - ./docker/db/data:/var/lib/mysql
134
+
135
+ - ./docker/db/my.cnf:/etc/mysql/conf.d/my.cnf
136
+
137
+ - ./docker/db/sql:/docker-entrypoint-initdb.d
138
+
139
+ ports:
140
+
141
+ - 3306:3306
142
+
143
+ build:
144
+
145
+ context: .
146
+
147
+ dockerfile: Dockerfile1
148
+
149
+
150
+
151
+ ```
152
+
87
153
 
88
154
 
89
155
  ```Java

3

説明を修正

2020/10/13 11:36

投稿

Linkey
Linkey

スコア77

test CHANGED
File without changes
test CHANGED
@@ -150,6 +150,14 @@
150
150
 
151
151
  ```
152
152
 
153
+ 【動作確認手順】
154
+
155
+ ①STSを起動する。(ionicからのリクエストを待つ)
156
+
157
+ ②Dockerを起動する(外部アクセスを許可)
158
+
159
+ ③ng serveでアプリ起動
160
+
153
161
 
154
162
 
155
163
  ionicを起動してリクエストを実行したところ以下のエラーとなってしまいました。

2

説明を修正

2020/10/13 11:24

投稿

Linkey
Linkey

スコア77

test CHANGED
File without changes
test CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  STS(Spring Tool Suite)でWebアプリケーション実装
16
16
 
17
- DockerでUbuntuを起動してionicからリクエストを受け付ける
17
+ DockerでUbuntuを起動してionicからリクエストを受け付ける(8080ポートを開放)
18
18
 
19
19
 
20
20
 

1

説明の修正

2020/10/07 13:56

投稿

Linkey
Linkey

スコア77

test CHANGED
File without changes
test CHANGED
@@ -15,6 +15,10 @@
15
15
  STS(Spring Tool Suite)でWebアプリケーション実装
16
16
 
17
17
  DockerでUbuntuを起動してionicからリクエストを受け付ける
18
+
19
+
20
+
21
+ 動作確認のために以下のように実装しました。
18
22
 
19
23
 
20
24
 
@@ -148,7 +152,7 @@
148
152
 
149
153
 
150
154
 
151
- ionicを起動したところ以下のエラーとなってしまいました。
155
+ ionicを起動してリクエストを実行したところ以下のエラーとなってしまいました。
152
156
 
153
157
  Access to XMLHttpRequest at 'http://XXX.XXX.X.X:8080/getToken' from origin 'http://localhost:8100' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
154
158