secutorpro's picture
entrypoint
b1857d5 verified
Raw History Blame Contribute Delete
952 Bytes
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}`));