Created
November 7, 2018 09:48
-
-
Save magicspon/8dc6de464f6491d7f3404672515d9a33 to your computer and use it in GitHub Desktop.
using https with next
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const https = require('https') | |
const { parse } = require('url') | |
const next = require('next') | |
const fs = require('fs') | |
const dev = process.env.NODE_ENV !== 'production' | |
const app = next({ dev }) | |
const handle = app.getRequestHandler() | |
const options = { | |
key: fs.readFileSync('private/key.pem'), | |
cert: fs.readFileSync('private/cert.pem') | |
} | |
app.prepare().then(() => { | |
https | |
.createServer(options, (req, res) => { | |
// Be sure to pass `true` as the second argument to `url.parse`. | |
// This tells it to parse the query portion of the URL. | |
const parsedUrl = parse(req.url, true) | |
handle(req, res, parsedUrl) | |
}) | |
.listen(8000, err => { | |
if (err) throw err | |
// eslint-disable-next-line no-console | |
console.log('> Ready on https://localhost:8000') | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment