feat(server): add Express REST API, security middleware, and multiplexed WebSocket hub
This commit is contained in:
parent
6520b81d82
commit
9cedd83a07
7 changed files with 1538 additions and 0 deletions
46
src/server/index.ts
Normal file
46
src/server/index.ts
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import path from 'node:path';
|
||||
import { createGCoordinatorServer } from './app.js';
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const dataDir = path.resolve(process.env.GCOORD_DATA_DIR ?? './data');
|
||||
const port = Number(process.env.PORT ?? 3000);
|
||||
const host = process.env.HOST ?? '0.0.0.0';
|
||||
const trustCloudflare = process.env.TRUST_CLOUDFLARE === 'true';
|
||||
const secretFilePath =
|
||||
process.env.GCOORD_MASTER_KEY_FILE ?? '/run/secrets/gcoord_master_key';
|
||||
const envMasterKey = process.env.GCOORD_MASTER_KEY;
|
||||
|
||||
const instance = await createGCoordinatorServer({
|
||||
dataDir,
|
||||
port: Number.isFinite(port) ? port : 3000,
|
||||
host,
|
||||
secretFilePath,
|
||||
envMasterKey,
|
||||
trustCloudflare,
|
||||
});
|
||||
|
||||
console.log(
|
||||
`GCoordinator listening on http://${host}:${instance.port} (vault=${instance.vaultService.state}, data=${dataDir})`,
|
||||
);
|
||||
|
||||
let shuttingDown = false;
|
||||
const shutdown = async (signal: string) => {
|
||||
if (shuttingDown) return;
|
||||
shuttingDown = true;
|
||||
console.log(`Received ${signal}; shutting down gracefully...`);
|
||||
await instance.close();
|
||||
process.exit(0);
|
||||
};
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
void shutdown('SIGINT');
|
||||
});
|
||||
process.on('SIGTERM', () => {
|
||||
void shutdown('SIGTERM');
|
||||
});
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error('Fatal startup error:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue