[swagger] Failed to fetch. Possible Reasons: CORS, Network Failure, URL scheme must be "http" or "https" for CORS request
Curl ๋ช ๋ น์ด ํ์ธํด๋ณด๋ https๊ฐ ์๋ http ๋ก ์์ฒญ์ด ๊ฐ์์ ํ์ธํ ์ ์์๋ค.
์คํํ๊ณ ์๋ ์๋ฒ๋ HTTPS ์ธ๋ฐ HTTP๋ก ์์ฒญ์ ๋ณด๋ด์ ๋ฐ์ํ ๋ฌธ์ ์ด๋ค.
CORS์ ๋ํด ์ ๋ฆฌ ์ ํด๋์ ๋ธ๋ก๊ทธ ์ฒจ๋ถ)
๐ ์ ๋ช ๋์ CORS ๊ฐ๋ & ํด๊ฒฐ๋ฒ - ์ ๋ฆฌ ๋ํ์ ๐
์ ๋ช ๋์ CORS ์๋ฌ ๋ฉ์ธ์ง ์น ๊ฐ๋ฐ์ ํ๋ค๋ณด๋ฉด ๋ฐ๋์ ๋ง์ฃผ์น๋ ๋ฉ๋ฉ ๊ฐ์ ์๋ฌ๊ฐ ๋ฐ๋ก CORS ์ด๋ค. ์น ๊ฐ๋ฐ์ ์ ์ ์ ๊ณ ์์ด๋ผ๊ณ ํ ์ ๋๋ก, CORS๋ ๋๊ตฌ๋ ํ ๋ฒ ์ ๋๋ ๊ฒช๊ฒ ๋๋ค๊ณ ํด๋ ๊ณผ์ธ์ด
inpa.tistory.com
Swagger ์ค์ ์ ๋ฐ๊ฟ์ฃผ๋ฉด ๋๋ค
serverUrl์ active profile (local, prod ๋ง๋ค ๋ค๋ฅด๊ฒ ์ค์ ํ๋๋ก ํ์๋ค)
@Configuration
public class SwaggerConfig {
@Value("${swagger.url}")
private String serverUrl;
@Bean
public OpenAPI springOpenApi() {
return new OpenAPI()
.components(createComponents())
.addServersItem(createServer());
}
private Server createServer() {
return new Server().url(serverUrl);
}
}