Created
June 4, 2024 12:29
-
-
Save rakeshtembhurne/cd6aa2b30c3ec9574eae5b95166eab35 to your computer and use it in GitHub Desktop.
NodeJS: NextJS Server to create production server with locally. created https certificates
This file contains hidden or 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 { createServer } = require("https"); | |
const { parse } = require("url"); | |
const next = require("next"); | |
const fs = require("fs"); | |
const port = 3000; | |
// const dev = process.env.NODE_ENV !== "production"; | |
const dev = false; | |
const app = next({ dev }); | |
const handle = app.getRequestHandler(); | |
const httpsOptions = { | |
key: fs.readFileSync("./certificates/localhost-key.pem"), | |
cert: fs.readFileSync("./certificates/localhost.pem"), | |
}; | |
app.prepare().then(() => { | |
createServer(httpsOptions, (req, res) => { | |
const parsedUrl = parse(req.url, true); | |
handle(req, res, parsedUrl); | |
}).listen(port, (err) => { | |
if (err) throw err; | |
console.log("ready - started server on url: https://localhost:" + port); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment