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', + }, }