import { createServer } from "http";
import next from "next";
import { AppData } from "../data/app-data";

const port = AppData["WebPort"] || 3000;
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();

app.prepare().then(() => {
    createServer((req, res) => {
        if (!req.url) {
            return;
        }

        handle(req, res);
    }).listen(port);

    console.log(
        `> Server listening at http://localhost:${port} as ${
            dev ? "development" : process.env.NODE_ENV
        }`,
    );
});
