Spaces:
Paused
Paused
File size: 952 Bytes
b8a98f2 b1857d5 b8a98f2 b1857d5 b8a98f2 b1857d5 b8a98f2 b1857d5 b8a98f2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import express from 'express';
import cors from 'cors';
import http from 'node:http';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { WebSocketServer } from 'ws';
import authRouter, { requireAuth } from './auth.js';
import routes from './routes.js';
import Hub from './realtime.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const PORT = Number(process.env.PORT || 8080);
const app = express();
app.use(cors());
app.use(express.json());
app.use('/api', authRouter);
app.use('/api', requireAuth, routes);
const webDist = path.join(__dirname, '..', 'web', 'dist');
app.use(express.static(webDist));
app.get('*', (req, res) => res.sendFile(path.join(webDist, 'index.html')));
const server = http.createServer(app);
const wss = new WebSocketServer({ server, path: '/ws' });
const hub = new Hub(wss);
app.set('hub', hub);
server.listen(PORT, () => console.log(`[dispatch] listening on :${PORT}`)); |