Files
aifo-portal-web/server.js
T
steven 4d30803b60 Initial commit: AIFO official portal web.
Add static site, shared layout, and Node dev server with standard .gitignore.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-30 15:29:50 +08:00

43 lines
1.2 KiB
JavaScript

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 <pid> /F");
console.error(" 2) Use another port:");
console.error(" set PORT=3001 && npm start");
process.exit(1);
}
throw err;
});