SPB Git

Repository Public

serve.ts 4.4 KB 90 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : KA Maps Engine8 * File             : studio/e2e/serve.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// Pile jetable pour les essais de bout en bout : schéma temporaire dans kamaps_test, thèmes du dépôt43// importés, Studio sur localhost:8915 (RP « localhost »), service de manifeste sur 8916.44import { randomBytes } from 'node:crypto';45import { readdirSync, readFileSync, writeFileSync } from 'node:fs';46import { createServer } from 'node:http';47import { dirname, join } from 'node:path';48import { fileURLToPath } from 'node:url';49import { configFromEnv, createApp } from '../../server/km-maps/src/app.ts';50import { createStudio } from '../server/app.ts';51import { createInvite } from '../server/auth.ts';52import { connect, migrate } from '../server/db.ts';53import { opsConfigFromEnv } from '../server/ops.ts';54import { importThemes } from '../server/themes.ts';5556const here = dirname(fileURLToPath(import.meta.url));57const themesDir = join(here, '..', '..', 'themes');58const db = connect(process.env.STUDIO_TEST_DB_URL!, `e2e_${randomBytes(4).toString('hex')}`);59await migrate(db);60const load = (f: string) => JSON.parse(readFileSync(join(themesDir, f), 'utf8'));61await importThemes(db, { id: null, name: 'e2e' }, readdirSync(themesDir).filter((f) => f.endsWith('.json')).sort().map((name) => ({ name, doc: load(name) })), ['louka', 'immoka', 'vraiprix', 'valoplex'].map((app) => ({ app, doc: load(`brands/${app}.json`) })), 0);6263const ORIGIN = 'http://localhost:8915';64const studio = createStudio(db, {65  auth: { rpId: 'localhost', rpName: 'KA Maps Studio', origin: ORIGIN, cookieName: 'kms', secureCookie: false, sessionHours: 12, idleMinutes: 120 },66  ops: opsConfigFromEnv({ STUDIO_COLLECT: '0' } as any),67  webDir: join(here, '..', 'web', 'dist'),68  sdkDir: process.env.E2E_SDK_DIR ?? '/var/lib/kamaps/sdk',69  tiler: 'http://127.0.0.1:8901',70  publicMaps: 'http://localhost:8916',71});72const maps = createApp(db.pool as any, configFromEnv({ KM_MAPS_SCHEMA: db.schema, KM_POLL_MS: '200', KM_PUBLIC_MAPS: 'http://localhost:8916', KM_STATIC_CACHE: `/tmp/kms-e2e-static-${db.schema}`, KM_SDK_DIR: join(here, 'no-sdk') } as any));73await maps.start();74const s1 = createServer(studio.handler).listen(8915, '127.0.0.1');75const s2 = createServer(maps.handler).listen(8916, '127.0.0.1');76const a = await createInvite(db, 'Simone Essai', 'simone@example.org');77const b = await createInvite(db, 'Erik Essai', 'erik@example.org');78writeFileSync(join(here, '.state.json'), JSON.stringify({ origin: ORIGIN, maps: 'http://localhost:8916', tokens: [a.token, b.token], schema: db.schema }));79console.log('pile e2e prête');80const stop = async () => {81  s1.close(); s2.close(); s1.closeAllConnections(); s2.closeAllConnections();82  studio.stop();83  await maps.stop().catch(() => {});84  await db.pool.query(`DROP SCHEMA ${db.schema} CASCADE`).catch(() => {});85  await db.pool.end().catch(() => {});86  process.exit(0);87};88process.on('SIGTERM', stop);89process.on('SIGINT', stop);90
Files main
Menu

Theme