feat: initialize sunrise with 100-player shared rooms
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { createApp } from './app.ts';
|
||||
import { MemoryVisitStore, MongoVisitStore, type VisitStore } from './visits.ts';
|
||||
|
||||
async function main() {
|
||||
const port = Number(process.env.PORT ?? 3000);
|
||||
if (!Number.isInteger(port) || port < 0 || port > 65535) throw new Error('Invalid PORT');
|
||||
if (process.env.VISIT_STORE && !['memory', 'mongo'].includes(process.env.VISIT_STORE)) throw new Error('Invalid VISIT_STORE');
|
||||
let visitStore: VisitStore;
|
||||
if (process.env.VISIT_STORE === 'memory') {
|
||||
console.warn('VISIT_STORE=memory: visit history is volatile; development/tests only.');
|
||||
visitStore = new MemoryVisitStore();
|
||||
} else {
|
||||
visitStore = await MongoVisitStore.connect(process.env.MONGODB_URI ?? 'mongodb://172.16.0.7:27017', process.env.MONGODB_DATABASE ?? 'sunrise');
|
||||
}
|
||||
const app = createApp({ visitStore,
|
||||
allowedOrigins: process.env.ALLOWED_ORIGINS?.split(',').map(origin => origin.trim()).filter(Boolean) });
|
||||
const stop = () => { void app.close().catch(error => { console.error('Shutdown failed', error); process.exitCode = 1; }); };
|
||||
process.once('SIGINT', stop); process.once('SIGTERM', stop);
|
||||
app.httpServer.once('error', error => { console.error('HTTP server failed', error); process.exitCode = 1; stop(); });
|
||||
app.httpServer.listen(port, process.env.HOST ?? '127.0.0.1', () => {
|
||||
console.log(`Sunrise single-instance server listening on ${process.env.HOST ?? '127.0.0.1'}:${(app.httpServer.address() as { port: number }).port}`);
|
||||
});
|
||||
}
|
||||
void main().catch(error => { console.error('Server startup failed; admission disabled', error); process.exitCode = 1; });
|
||||
Reference in New Issue
Block a user