Files
HexaHost-GameCloud/apps/web/src/server.ts
smueller 4104daaf75
Some checks failed
CI / Node — lint, typecheck, test, build (push) Failing after 9s
CI / Go — node-agent tests (push) Failing after 55s
CI / Go — edge-gateway build (push) Successful in 13s
initial commit2
2026-06-26 10:45:58 +02:00

50 lines
1.4 KiB
TypeScript

import http from "node:http";
import fs from "node:fs";
import path from "node:path";
const port = Number(process.env.WEB_PORT ?? process.env.PORT ?? 3000);
const appName = process.env.APP_NAME ?? "HexaHost GameCloud";
const publicDir = path.join(process.cwd(), "public");
const indexHtml = `<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>${appName}</title>
</head>
<body>
<main>
<h1>${appName}</h1>
<p>Phase 0 — Web stub. Next.js UI arrives in Phase 1.</p>
</main>
</body>
</html>`;
const server = http.createServer((req, res) => {
if (req.url === "/api/health") {
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify({ status: "ok", service: "web", phase: "0" }));
return;
}
if (req.url === "/" || req.url === "/index.html") {
const filePath = path.join(publicDir, "index.html");
if (fs.existsSync(filePath)) {
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
fs.createReadStream(filePath).pipe(res);
return;
}
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
res.end(indexHtml);
return;
}
res.writeHead(404, { "Content-Type": "application/json" });
res.end(JSON.stringify({ status: "not_found" }));
});
server.listen(port, () => {
console.log(JSON.stringify({ level: "info", msg: "web listening", port }));
});