// Мини-сервер стенда (TPTIP-6): слушает $PORT, /healthz → 200, отдаёт файлы приложения по белому списку. // Пока index.html нет, на «/» отдаётся страница продукта about.html. const http = require('node:http'); const fs = require('node:fs'); const path = require('node:path'); const DIR = process.env.APP_DIR || __dirname; const FILES = { '/gym-plan.i18n.js': ['gym-plan.i18n.js', 'text/javascript; charset=utf-8'], '/': ['index.html', 'text/html; charset=utf-8'], '/index.html': ['index.html', 'text/html; charset=utf-8'], '/manifest.webmanifest': ['manifest.webmanifest', 'application/manifest+json'], '/sw.js': ['sw.js', 'text/javascript; charset=utf-8'], '/icon.svg': ['icon.svg', 'image/svg+xml'], '/about.html': ['about.html', 'text/html; charset=utf-8'], '/about.i18n.json': ['about.i18n.json', 'application/json; charset=utf-8'] }; const FALLBACK = { '/': ['about.html', 'text/html; charset=utf-8'] }; function send(res, f, fallback) { fs.readFile(path.join(DIR, f[0]), (err, buf) => { if (err && err.code === 'ENOENT' && fallback) return send(res, fallback, null); if (err && err.code === 'ENOENT') { res.writeHead(404); return res.end('not found'); } if (err) { res.writeHead(500); return res.end('error'); } res.writeHead(200, { 'content-type': f[1], 'cache-control': 'no-cache' }); res.end(buf); }); } function createServer() { return http.createServer((req, res) => { const url = (req.url || '/').split('?')[0]; if (url === '/healthz') { res.writeHead(200, { 'content-type': 'text/plain' }); return res.end('ok'); } const f = FILES[url]; if (!f) { res.writeHead(404); return res.end('not found'); } send(res, f, FALLBACK[url]); }); } if (require.main === module) createServer().listen(Number(process.env.PORT) || 3000, '0.0.0.0'); module.exports = { createServer };