56 lines
2.9 KiB
JavaScript
56 lines
2.9 KiB
JavaScript
const Sentry = require('@sentry/node');
|
|
if (process.env.SENTRY_DSN) Sentry.init({ dsn: process.env.SENTRY_DSN, release: process.env.SENTRY_RELEASE, environment: process.env.SENTRY_ENVIRONMENT || 'dev', sendDefaultPii: false });
|
|
// Мини-сервер стенда (TPTIP-6): слушает $PORT, /healthz → 200, отдаёт файлы приложения по белому списку.
|
|
// По ссылке открывается трекер; каталог рецептов доступен на /recipes.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'],
|
|
'/recipes.html': ['recipes.html', 'text/html; charset=utf-8'],
|
|
'/recipes.css': ['recipes.css', 'text/css; charset=utf-8'],
|
|
'/telemetry.js': ['generated/telemetry.js', 'text/javascript; charset=utf-8'],
|
|
'/recipes.js': ['recipes.js', 'text/javascript; charset=utf-8'],
|
|
'/recipes-core.js': ['recipes-core.js', 'text/javascript; charset=utf-8'],
|
|
'/recipes.data.json': ['recipes.data.json', 'application/json; charset=utf-8'],
|
|
'/recipes.i18n.json': ['recipes.i18n.json', 'application/json; charset=utf-8'],
|
|
'/recipes-status.i18n.js': ['recipes-status.i18n.js', 'text/javascript; charset=utf-8'],
|
|
'/assets/oats.jpg': ['assets/oats.jpg', 'image/jpeg'],
|
|
'/assets/chicken.jpg': ['assets/chicken.jpg', 'image/jpeg'],
|
|
'/assets/salad.jpg': ['assets/salad.jpg', 'image/jpeg']
|
|
};
|
|
|
|
function send(res, f) {
|
|
fs.readFile(path.join(DIR, f[0]), (err, buf) => {
|
|
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'); }
|
|
if (url === '/telemetry.json') {
|
|
res.writeHead(200, { 'content-type': 'application/json', 'cache-control': 'no-store' });
|
|
return res.end(JSON.stringify({ dsn: process.env.PUBLIC_SENTRY_DSN || '', release: process.env.SENTRY_RELEASE, environment: process.env.SENTRY_ENVIRONMENT || 'dev' }));
|
|
}
|
|
const f = FILES[url];
|
|
if (!f) { res.writeHead(404); return res.end('not found'); }
|
|
send(res, f);
|
|
});
|
|
}
|
|
|
|
if (require.main === module) createServer().listen(Number(process.env.PORT) || 3000, '0.0.0.0');
|
|
module.exports = { createServer };
|