SPB Git

Repository Public

main.ts 3.2 KB 83 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : KA Maps Engine8 * File             : studio/server/main.ts9 * Module           : studio10 * 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// KA Maps Studio — maps-admin.spboucher.ai (privé).43import { createServer } from 'node:http';44import { dirname, join } from 'node:path';45import { fileURLToPath } from 'node:url';46import { createStudio } from './app.ts';47import { authConfigFromEnv } from './auth.ts';48import { connect, migrate } from './db.ts';49import { opsConfigFromEnv } from './ops.ts';5051const url = process.env.STUDIO_DB_URL;52if (!url) {53  console.error('STUDIO_DB_URL requis');54  process.exit(2);55}56const here = dirname(fileURLToPath(import.meta.url));57const db = connect(url, process.env.STUDIO_SCHEMA ?? 'studio');58const applied = await migrate(db);59if (applied.length) console.log(`migrations appliquées : ${applied.join(', ')}`);60const studio = createStudio(db, {61  auth: authConfigFromEnv(),62  ops: opsConfigFromEnv(),63  webDir: process.env.STUDIO_WEB_DIR ?? join(here, '..', 'web', 'dist'),64  sdkDir: process.env.KM_SDK_DIR ?? '/var/lib/kamaps/sdk',65  tiler: process.env.KM_TILER_LOCAL ?? 'http://127.0.0.1:8901',66  publicMaps: process.env.KM_PUBLIC_MAPS ?? 'https://maps.spboucher.ai',67});68studio.collector.start();69const servers = (process.env.STUDIO_LISTEN ?? '127.0.0.1:8905').split(',').map((addr) => {70  const [host, port] = addr.trim().split(':');71  const s = createServer({ requestTimeout: 60_000, headersTimeout: 10_000, maxHeaderSize: 16384 }, studio.handler);72  s.listen(Number(port), host, () => console.log(`studio écoute sur ${host}:${port}`));73  return s;74});75async function shutdown() {76  for (const s of servers) s.close();77  studio.stop();78  await db.pool.end().catch(() => {});79  process.exit(0);80}81process.on('SIGTERM', shutdown);82process.on('SIGINT', shutdown);83
Files main
Menu

Theme