27 lines
799 B
JavaScript
27 lines
799 B
JavaScript
const { createServer } = require('http');
|
|
const { parse } = require('url');
|
|
const next = require('next');
|
|
|
|
const dev = process.env.NODE_ENV !== 'production';
|
|
const hostname = process.env.HOSTNAME || 'localhost';
|
|
const port = parseInt(process.env.PORT || '3000', 10);
|
|
|
|
const app = next({ dev, hostname, port });
|
|
const handle = app.getRequestHandler();
|
|
|
|
app.prepare().then(() => {
|
|
createServer((req, res) => {
|
|
// Trust proxy headers from Cloudflare tunnel
|
|
const proto = req.headers['x-forwarded-proto'];
|
|
if (proto === 'https') {
|
|
req.connection.encrypted = true;
|
|
}
|
|
|
|
const parsedUrl = parse(req.url, true);
|
|
handle(req, res, parsedUrl);
|
|
}).listen(port, hostname, (err) => {
|
|
if (err) throw err;
|
|
console.log(`> Ready on http://${hostname}:${port}`);
|
|
});
|
|
});
|