Skip to content

Commit ba3604e

Browse files
authored
Merge pull request #40 from EKEC-crew/develop
✨CORS 설정 반영을 위한 PR
2 parents 6b0b9eb + 1ad554f commit ba3604e

1 file changed

Lines changed: 20 additions & 15 deletions

File tree

src/index.js

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const port = process.env.PORT;
2727
*/
2828
app.use((req, res, next) => {
2929
res.success = (success) => {
30-
return res.json({ resultType: "SUCCESS", error: null, data:success });
30+
return res.json({ resultType: "SUCCESS", error: null, data: success });
3131
};
3232

3333
res.error = ({ errorCode = "unknown", reason = null, data = null }) => {
@@ -42,24 +42,29 @@ app.use((req, res, next) => {
4242
});
4343
/** session */
4444
app.use(
45-
session({
46-
cookie: {
47-
maxAge: 7 * 24 * 60 * 60 * 1000, // ms
48-
},
49-
resave: false,
50-
saveUninitialized: false,
51-
secret: process.env.EXPRESS_SESSION_SECRET,
52-
store: new PrismaSessionStore(prisma, {
53-
checkPeriod: 2 * 60 * 1000, // ms
54-
dbRecordIdIsSessionId: true,
55-
dbRecordIdFunction: undefined,
56-
}),
57-
})
45+
session({
46+
cookie: {
47+
maxAge: 7 * 24 * 60 * 60 * 1000, // ms
48+
},
49+
resave: false,
50+
saveUninitialized: false,
51+
secret: process.env.EXPRESS_SESSION_SECRET,
52+
store: new PrismaSessionStore(prisma, {
53+
checkPeriod: 2 * 60 * 1000, // ms
54+
dbRecordIdIsSessionId: true,
55+
dbRecordIdFunction: undefined,
56+
}),
57+
})
5858
);
5959
app.use(passport.initialize());
6060
app.use(passport.session());
6161

62-
app.use(cors()); // cors 방식 허용
62+
const corsOptions = {
63+
origin: [process.env.LOCAL_ORIGIN, process.env.PROD_ORIGIN],
64+
credentials: true,
65+
};
66+
67+
app.use(cors(corsOptions)); // cors 방식 허용
6368
app.use(express.static("public")); // 정적 파일 접근
6469
app.use(express.json()); // request의 본문을 json으로 해석할 수 있도록 함 (JSON 형태의 요청 body를 파싱하기 위함)
6570
app.use(express.urlencoded({ extended: false })); // 단순 객체 문자열 형태로 본문 데이터 해석

0 commit comments

Comments
 (0)