vue와 express의 연동 프로젝트를 진행 중 개발자라면 한번쯤 겪어 봤을 cors문제에 직면했다.
express에 npm install cors를 하고 미들웨어를 추가했다.
app.use(
cors({
origin: "http://localhost:8080/",
credentials: true,
})
);
vue.config에 devServer를 추가하여
proxy: {
"/api": {
target: "http://127.0.0.1:3000/api",
changeOrigin: true,
pathRewrite: {
"^api": "",
},
},
},
를 추가했는데 계속 cors문제가 떴다.
분명 주소도 맞게 썼는데...
그러다
app.use(
cors({
origin: "http://localhost:8080",
credentials: true,
})
);
8080뒤에 있는 /를 지워봤는데 된다...