๊ฐ์ฅ ๊น๋ํ ๋ฐฉ๋ฒ: ํ๋ก์ ๋ฐฉ์(Next rewrites) + LAN ์ ์
โ ๋ชจ๋ฐ์ผ์ ๋งฅ๋ถ์ :3000
๋ง ํธ์ถ, Next๊ฐ ๋ด๋ถ์์ 127.0.0.1:8080
(๋ฐฑ์๋)๋ก ํ๋ก์ โ CORS/localhost ๋ฌธ์ ์์
ngrok ์ธ ๋: ํ๋ก์ ์ ์ธ ๊ฑฐ๋ผ๋ฉด ๋ฐฑ์๋ CORS์ ngrok ๋๋ฉ์ธ์ ํ์ฉํด์ผ ํจ.
๋ชจ๋ฐ์ผ์ด localhost
์ ๋ชป ๋ถ๋ ์ด์ : ๋ชจ๋ฐ์ผ์์ localhost/127.0.0.1
์ โ๋ชจ๋ฐ์ผ ์๊ธฐ ์์ โ์ด๊ธฐ ๋๋ฌธ.
Swagger๋ฅผ ํฐ์์ ์ง์ ๋ณด๋ ค๋ฉด: ๋ฐฑ์๋๋ฅผ 0.0.0.0
๋ก ๋ฐ์ธ๋ฉํ๊ณ http://<๋งฅIP>:8080/swaggerโฆ
๋ก ์ ์.
๋ธ๋ผ์ฐ์ ๋ ํญ์ ๊ฐ์ ์ค๋ฆฌ์ง(/api
, /oauth2
)๋ง ๋ถ๋ฅด๊ณ , Next๊ฐ ๋ฉํ ๋ด๋ถ์์ ๋ฐฑ์๋๋ก ์ฐ๊ฒฐํฉ๋๋ค.
# ์ผ์ ์คํ
npx next dev --hostname 0.0.0.0 -p 3000
# (๊ถ์ฅ) package.json
"scripts": {
"dev:lan": "next dev --hostname 0.0.0.0 -p 3000"
}
next.config.mjs
์ ํ๋ก์(๋ฆฌ๋ผ์ดํธ) ์ถ๊ฐ// next.config.mjs
const API_ORIGIN = process.env.API_ORIGIN || '<http://127.0.0.1:8080>';
const nextConfig = {
// ...๊ธฐ์กด ์ต์
์ ์ง
async rewrites() {
return [
{ source: '/api/:path*', destination: `${API_ORIGIN}/api/:path*` },
];
},
};
export default nextConfig;
๊ฐ๋ฐ ์๋ฒ ์ฌ์์ ํ์.
// axios ์ธ์คํด์ค
import axios from 'axios';
export const axiosApi = axios.create({
baseURL: '/api',
withCredentials: true, // ์ฟ ํค/์ธ์
์ด๋ฉด
});
export const axiosLogin = axios.create({
baseURL: '/oauth2',
withCredentials: true,
});
์ ๋ URL ๊ธ์ง: http://localhost:8080/...๋ก ์ง์ ๋๋ฆฌ๋ฉด ๋ชจ๋ฐ์ผ์์ ๋ค์ ์คํจํฉ๋๋ค.
ipconfig getifaddr en0
โ ์) 192.168.134.166
http://192.168.134.166:3000
์ ์/api/...
*๋ก๋ง ๋ณด์ด๋ฉด ์ฑ๊ณต