21 lines
1.3 KiB
JavaScript
21 lines
1.3 KiB
JavaScript
import { createReadStream, existsSync, statSync } from 'node:fs';
|
|
import { createServer } from 'node:http';
|
|
import { extname, join, normalize } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const root = join(fileURLToPath(new URL('..', import.meta.url)), 'dist');
|
|
const host = process.env.KAPTAN_GROUND_SUITE_HOST ?? '127.0.0.1';
|
|
const port = Number(process.env.KAPTAN_GROUND_SUITE_PORT ?? '4173');
|
|
const mime = { '.html': 'text/html; charset=utf-8', '.js': 'text/javascript; charset=utf-8', '.css': 'text/css; charset=utf-8', '.png': 'image/png', '.svg': 'image/svg+xml' };
|
|
|
|
createServer((request, response) => {
|
|
const requested = normalize(decodeURIComponent((request.url ?? '/').split('?')[0])).replace(/^(\.\.[/\\])+/, '');
|
|
let path = join(root, requested === '/' ? 'index.html' : requested);
|
|
if (!path.startsWith(root) || !existsSync(path) || statSync(path).isDirectory()) path = join(root, 'index.html');
|
|
response.writeHead(200, { 'Content-Type': mime[extname(path)] ?? 'application/octet-stream', 'Cache-Control': 'no-store' });
|
|
createReadStream(path).pipe(response);
|
|
}).listen(port, host, () => {
|
|
console.log(`Kaptan Ground Suite: http://${host}:${port}`);
|
|
console.log('SIMULATED DATA ONLY — no real vehicle connection or command authority.');
|
|
});
|