live-scoreboard/api/server.js
2026-11-24 11:14:10 +08:00

24 lines
720 B
JavaScript

import express from 'express';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { ScoreboardStore, createApiHandler } from './scoreboard.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const frontendDir = path.resolve(__dirname, '..', 'frontend');
const app = express();
const store = new ScoreboardStore();
app.use('/api', createApiHandler(store));
app.use(express.static(frontendDir));
app.get('*', (_req, res) => {
res.sendFile(path.join(frontendDir, 'index.html'));
});
const port = Number(process.env.PORT || 3000);
app.listen(port, '0.0.0.0', () => {
console.log(`live-scoreboard listening on http://0.0.0.0:${port}`);
});