[250519] TIL
Today I Learned (2025-05-19)
오늘의 커밋 및 작업 내용
로컬 개발 환경에서 시큐어 토큰 사용하는 백엔드 서버 사용하기
1. HTTPS 연결
Next.js –experimental-https 기능
"scripts": {
"dev": "next dev --turbopack --experimental-https"
}
2. CORS 오류가 발생한다면 ?
proxy 설정
// next.config.js
module.exports = {
async rewrites() {
return [
{
source: "/api/:path*",
destination: "https://be.dolpin.site/api/:path*",
},
];
},
};
// ❌ 여전히 이걸 쓰고 있다면:
fetch("https://be.dolpin.site/api/v1/auth/oauth"); // ← 이건 직접 cross-origin 요청
// ✅ 이렇게 바꿨어야 해:
fetch("/api/v1/auth/oauth"); // ← 이건 rewrite 통해 Next 서버가 중계
[ 브라우저 ]
|
| fetch('/api/v1/auth/oauth')
↓
[ Next.js 서버 (localhost:3000)]
|
| → rewrites → https://be.dolpin.site/api/v1/auth/oauth
↓
[ 백엔드 서버 ]
서버 <-> 서버 통신에는 CORS가 없을까?
- 브라우저 보안 정책이고, 서버 간 요청에는 적용되지 않는다.
Leave a comment