Skip to content

Instantly share code, notes, and snippets.

@magicspon
Created November 7, 2018 09:48
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save magicspon/8dc6de464f6491d7f3404672515d9a33 to your computer and use it in GitHub Desktop.
Save magicspon/8dc6de464f6491d7f3404672515d9a33 to your computer and use it in GitHub Desktop.
using https with next
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