const path = require("path"); const express = require("express"); const app = express(); const ROOT = __dirname; const PORT = Number(process.env.PORT) || 3000; app.use(express.static(ROOT, { extensions: ["html"] })); app.get("/", function (_req, res) { res.sendFile(path.join(ROOT, "index.html")); }); app.get("/pages/:page", function (req, res, next) { const file = path.join(ROOT, "pages", req.params.page); res.sendFile(file, function (err) { if (err) next(); }); }); app.use(function (_req, res) { res.status(404).send("Not found"); }); const server = app.listen(PORT, function () { console.log("AIFO portal: http://localhost:" + PORT); }); server.on("error", function (err) { if (err.code === "EADDRINUSE") { console.error("Port " + PORT + " is already in use."); console.error(""); console.error("Options:"); console.error(" 1) Stop the process using port " + PORT + " (Windows):"); console.error(" netstat -ano | findstr :" + PORT); console.error(" taskkill /PID /F"); console.error(" 2) Use another port:"); console.error(" set PORT=3001 && npm start"); process.exit(1); } throw err; });