"use strict"; const http = require("node:http"); const messages = require("./messages.json"); function pickLang(req) { const q = new URL(req.url, "http://x").searchParams.get("lang"); if (q && messages[q]) return q; const al = String(req.headers["accept-language"] || "").toLowerCase(); for (const l of Object.keys(messages)) if (al.startsWith(l)) return l; return "ru"; } const esc = (s) => s.replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]); function page(lang) { const m = messages[lang]; return `${esc(m.title)}

${esc(m.title)}

${esc(m.whatTitle)}

${esc(m.what)}

${esc(m.useTitle)}

${esc(m.use)}

${esc(m.checkTitle)}

${esc(m.check)}

`; } function createServer() { return http.createServer((req, res) => { const path = new URL(req.url, "http://x").pathname; if (path === "/healthz") { res.writeHead(200, { "content-type": "text/plain" }); return res.end("ok"); } const lang = pickLang(req); if (path === "/") { res.writeHead(200, { "content-type": "text/html; charset=utf-8" }); return res.end(page(lang)); } res.writeHead(404, { "content-type": "text/plain; charset=utf-8" }); res.end(messages[lang].notFound); }); } if (require.main === module) { const port = Number(process.env.PORT) || 3000; createServer().listen(port, "0.0.0.0", () => console.log(`listening on ${port}`)); } module.exports = { createServer };