SPB Git

Repository Public

main.ts 3.1 KB 87 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : KA Maps Engine8 * File             : server/km-maps/src/main.ts9 * Module           : server10 * Repository       : https://git.spboucher.ai/ka-maps-engine11 * Created          : 2026-12-0112 * Last Modified    : 2026-12-0113 *14 * Author           : Simon-Pierre Boucher15 * Position         : Professor of Finance16 * Institution      : Université du Québec en Outaouais (UQO)17 * Organization     : SP Boucher18 * Website          : https://spboucher.ai19 * Git              : https://git.spboucher.ai20 *21 * Preferred Contact: support@spboucher.ai22 * Development      : dev@spboucher.ai23 * Support          : support@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// km-maps — service public de manifeste (maps.spboucher.ai). Lecture seule.43import { createServer } from 'node:http';44import pg from 'pg';45import { configFromEnv, createApp } from './app.ts';4647const url = process.env.KM_MAPS_DB_URL;48if (!url) {49  console.error('KM_MAPS_DB_URL requis');50  process.exit(2);51}52const pool = new pg.Pool({ connectionString: url, max: 6, idleTimeoutMillis: 30_000, statement_timeout: 5000 } as any);53pool.on('error', (e) => console.error(`pg : ${e.message}`));54const cfg = configFromEnv();55const app = createApp(pool, cfg);56await app.start();5758const servers = (process.env.KM_MAPS_LISTEN ?? '127.0.0.1:8904').split(',').map((addr) => {59  const [host, port] = addr.trim().split(':');60  const s = createServer({ requestTimeout: 30_000, headersTimeout: 10_000, keepAliveTimeout: 65_000, maxHeaderSize: 8192 }, app.handler);61  s.listen(Number(port), host, () => console.log(`km-maps écoute sur ${host}:${port}`));62  return s;63});64const [mh, mp] = (process.env.KM_MAPS_METRICS ?? '127.0.0.1:8914').split(':');65const ms = createServer((req, res) => {66  if (req.url === '/metrics') {67    res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });68    res.end(app.metricsText());69  } else {70    res.writeHead(404);71    res.end();72  }73});74ms.listen(Number(mp), mh);7576let stopping = false;77async function shutdown() {78  if (stopping) return;79  stopping = true;80  for (const s of [...servers, ms]) s.close();81  await app.stop().catch(() => {});82  await pool.end().catch(() => {});83  process.exit(0);84}85process.on('SIGTERM', shutdown);86process.on('SIGINT', shutdown);87
Files main
Menu

Theme