Skip to content

Instantly share code, notes, and snippets.

@rakeshtembhurne
Created June 4, 2024 12:29
Show Gist options
  • Save rakeshtembhurne/cd6aa2b30c3ec9574eae5b95166eab35 to your computer and use it in GitHub Desktop.
Save rakeshtembhurne/cd6aa2b30c3ec9574eae5b95166eab35 to your computer and use it in GitHub Desktop.
NodeJS: NextJS Server to create production server with locally. created https certificates
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