fix: support ipv6 for nextjs

This commit is contained in:
Thanh Vu
2023-06-01 23:54:27 +07:00
committed by Thanh Vu
parent 316fb49339
commit 15b5f31a74
3 changed files with 35 additions and 2 deletions
+22
View File
@@ -0,0 +1,22 @@
import { createServer } from 'http';
import next from 'next';
import { parse } from 'url';
const hostname = process.env.HOST || '[::]';
const port = parseInt(process.env.PORT || '3000', 10);
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev, hostname, port });
const handle = app.getRequestHandler();
app.prepare().then(() => {
createServer((req, res) => {
const parsedUrl = parse(req.url!, true)
handle(req, res, parsedUrl)
}).listen(port);
// eslint-disable-next-line no-console
console.log(
`> Server listening at http://${hostname}:${port} as ${dev ? 'development' : process.env.NODE_ENV
}`
);
});