import express from 'express';
import next from 'next';
const dev = process.env.NODE_ENV !== 'production';
const hostname = 'localhost';
const port = 3000;
const app = next({ dev, hostname, port });
const handle = app.getRequestHandler();
global.clearRoutes = () => {
server._router.stack = server._router.stack.filter((k) => !(k && k.route && k.route.path));
};
app.prepare().then(() => {
const server = express();
server.all('*', (req, res) => {
const parsedUrl = new URL(req.url, `http://${req.headers.host}`);
const { pathname, query } = parsedUrl;
handle(req, res, parsedUrl);
});
server.listen(port, () => {
console.log(`> Ready on http://${hostname}:${port}`);
});
});