-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttps-server.js
More file actions
29 lines (25 loc) · 879 Bytes
/
https-server.js
File metadata and controls
29 lines (25 loc) · 879 Bytes
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
// https-server.js
const { createServer } = require('https')
const { parse } = require('url')
const next = require('next')
const fs = require('fs')
const path = require('path')
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
// const httpsOptions = {
// key: fs.readFileSync(path.join(__dirname, 'cert', 'key.pem')),
// cert: fs.readFileSync(path.join(__dirname, 'cert', 'cert.pem')),
// }
const httpsOptions = {
key: fs.readFileSync(path.join(__dirname, 'cert', 'localhost-key.pem')),
cert: fs.readFileSync(path.join(__dirname, 'cert', 'localhost.pem')),
}
app.prepare().then(() => {
createServer(httpsOptions, (req, res) => {
const parsedUrl = parse(req.url, true)
handle(req, res, parsedUrl)
}).listen(3000, () => {
console.log('> Ready on https://127.0.0.1:3000')
})
})