-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
40 lines (34 loc) · 984 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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('./key.pem'),
cert: fs.readFileSync('./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}`);
});
});