From 3a0308df97943f6c46f9d7636b2f5e52d702ec11 Mon Sep 17 00:00:00 2001 From: yoosangwook Date: Fri, 20 Dec 2024 10:04:55 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A8fix:=20session=20cookie=20option=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- package.json | 3 ++- server.js | 40 ++++++++++++++++++++++++++++++++++++++++ src/lib/session.js | 8 ++++---- 4 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 server.js diff --git a/.gitignore b/.gitignore index 52b4f8d4..315cf207 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,5 @@ next-env.d.ts #lock files yarn.lock -package-lock.json \ No newline at end of file +package-lock.json +certificates \ No newline at end of file diff --git a/package.json b/package.json index 1677b398..10bc804a 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint" + "lint": "next lint", + "serve": "node server.js" }, "dependencies": { "@nextui-org/react": "^2.4.2", diff --git a/server.js b/server.js new file mode 100644 index 00000000..43bc0266 --- /dev/null +++ b/server.js @@ -0,0 +1,40 @@ +const http = require('http') +const { parse } = require('url') +const next = require('next') + +const https = require('https') +const fs = require('fs') + +const dev = process.env.NODE_ENV !== 'production' +const app = next({ dev }) +const handle = app.getRequestHandler() + +const PORT = 3000 + +const httpsOptions = { + key: fs.readFileSync('./certificates/key.pem'), + cert: fs.readFileSync('./certificates/cert.pem'), +} + +app.prepare().then(() => { + http + .createServer((req, res) => { + const parsedUrl = parse(req.url, true) + handle(req, res, parsedUrl) + }) + .listen(PORT, (err) => { + if (err) throw err + console.log(`> Ready on http://localhost:${PORT}`) + }) + + // https 서버 추가 + https + .createServer(httpsOptions, (req, res) => { + const parsedUrl = parse(req.url, true) + handle(req, res, parsedUrl) + }) + .listen(PORT + 1, (err) => { + if (err) throw err + console.log(`> HTTPS: Ready on https://localhost:${PORT + 1}`) + }) +}) diff --git a/src/lib/session.js b/src/lib/session.js index bcedecf4..ff5a2078 100644 --- a/src/lib/session.js +++ b/src/lib/session.js @@ -3,8 +3,8 @@ export const defaultSession = {} export const sessionOptions = { password: process.env.SESSION_SECRET, cookieName: 'lama-session', - // cookieOptions: { - // httpOnly: true, - // secure: process.env.NODE_ENV === 'production', - // }, + cookieOptions: { + httpOnly: true, + secure: process.env.NODE_ENV === 'production', + }, }