1 parent
43347c1172
commit
6e15063502
122 files changed
+7848
-9828
No files matched your search
@@ -0,0 +1,20 @@
|
||||
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.');
|
||||
});
|
||||
Reference in new issue
Block a user