Skip to content

Commit

Permalink
fix : axios, server cors 쿠키 설정
Browse files Browse the repository at this point in the history
- express로 5000번에 서버를 만들고 send로 hi를 출력함
- mongodb연결후 shema 작성
  • Loading branch information
sheepdog13 committed Jan 30, 2024
1 parent 5c5632e commit 7cfec4d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
2 changes: 1 addition & 1 deletion client/src/_reducers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const asynsLoginFetch = createAsyncThunk(
"https://nodestudy-34u2.onrender.com/api/users/login",
formdata,
{
withCredentials: true,
withCredentials: true, // 쿠키 전송을 허용하는 옵션
}
);
return resp.data;
Expand Down
14 changes: 3 additions & 11 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,12 @@ const cookieparser = require("cookie-parser");
const { User } = require("./models/User");
const nodemailer = require("nodemailer");

const whitelist = ["http://localhost:3000", "http://sheepdog13.blog"];

const corsOptions = {
origin: function (origin, callback) {
if (whitelist.indexOf(origin) !== -1) {
// 만일 whitelist 배열에 origin인자가 있을 경우
callback(null, true); // cors 허용
} else {
callback(new Error("Not Allowed Origin!")); // cors 비허용
}
},
origin: ["http://localhost:3000/", "http://sheepdog13.blog"],
credentials: true, // 쿠키 전송을 허용
};

app.use(cors({ corsOptions, credential: "true" })); // 옵션을 추가한 CORS 미들웨어 추가
app.use(cors(corsOptions));

// application/x-www-form-urlencoded 이렇게된 데이터를 분석해서 가져올 수 있게 해준다.
app.use(bodyParser.urlencoded({ extended: true }));
Expand Down

0 comments on commit 7cfec4d

Please sign in to comment.