diff --git a/app.js b/app.js index 3914354..c582d3b 100644 --- a/app.js +++ b/app.js @@ -2,6 +2,7 @@ const express = require('express'); const conf = require('./src/common/config/index'); const expressLoader = require('./src/common/modules/express'); const initDB = require('./src/common/modules/mongodb'); +const { START_MESSAGE } = require('./src/common/constants/express'); const app = express(); @@ -10,7 +11,7 @@ const initServer = async () => { await initDB(); app.listen(conf.port, () => { - console.log(`app listening on http://localhost:${conf.port}`); + console.log(START_MESSAGE); }); }; diff --git a/src/common/config/index.js b/src/common/config/index.js index e28dcff..0b9b29e 100644 --- a/src/common/config/index.js +++ b/src/common/config/index.js @@ -25,4 +25,38 @@ const conf = { kakaoRestApiKey: process.env.KAKAO_REST_API_KEY, }; +switch (process.env.NODE_ENV) { + case 'production': + conf.cookieInAccessTokenOptions = { + httpOnly: false, + maxAge: 10 * 60 * 1000, + sameSite: 'Lax', + secure: true, + }; + conf.cookieInRefreshTokenOptions = { + httpOnly: true, + maxAge: 10 * 60 * 1000, + sameSite: 'Lax', + secure: true, + }; + conf.envMode = 'prod'; + break; + case 'development': + conf.cookieInAccessTokenOptions = { + httpOnly: false, + maxAge: 10 * 60 * 1000, + sameSite: 'Lax', + }; + conf.cookieInRefreshTokenOptions = { + httpOnly: true, + maxAge: 10 * 60 * 1000, + sameSite: 'Lax', + }; + 1; + conf.envMode = 'dev'; + break; + default: + console.error('NODE_ENV is not set correctly. It should be either production or development'); +} + module.exports = conf; diff --git a/src/common/constants/error-message.js b/src/common/constants/error-message.js index 1554ffc..fc4356b 100644 --- a/src/common/constants/error-message.js +++ b/src/common/constants/error-message.js @@ -24,6 +24,7 @@ const ErrorMessage = Object.freeze({ LOGIN_ERROR: '로그인중 오류가 발생하였습니다.', KAKAO_LOGIN_ERROR: '카카오 로그인중 오류가 발생하였습니다.', NO_REFRESH_TOKEN: 'refresh token이 존재하지 않습니다.', + REFRESH_TOKEN_ERROR: 'refresh token 검증중 오류가 발생하였습니다.', }); module.exports = ErrorMessage; diff --git a/src/common/constants/express.js b/src/common/constants/express.js new file mode 100644 index 0000000..3ff9f54 --- /dev/null +++ b/src/common/constants/express.js @@ -0,0 +1,13 @@ +const conf = require('../config'); + +const mode = { + dev: 'development', + prod: 'production', +}; + +exports.START_MESSAGE = ` +================================================================ +MURAKANO API Server has been started at localhost:${conf.port} +Mode : ${mode[conf.envMode]} +================================================================ +`;