Spaces:
Paused
Paused
entrypoint
Browse files- server/src/index.js +6 -9
server/src/index.js
CHANGED
|
@@ -9,24 +9,21 @@ import routes from './routes.js';
|
|
| 9 |
import Hub from './realtime.js';
|
| 10 |
|
| 11 |
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
| 12 |
-
const PORT = Number(process.env.PORT
|
| 13 |
|
| 14 |
const app = express();
|
| 15 |
app.use(cors());
|
| 16 |
app.use(express.json());
|
| 17 |
-
|
| 18 |
-
app.use('/api',
|
| 19 |
-
app.use('/api', requireAuth, routes); // everything else
|
| 20 |
|
| 21 |
const webDist = path.join(__dirname, '..', 'web', 'dist');
|
| 22 |
app.use(express.static(webDist));
|
| 23 |
-
app.
|
| 24 |
-
if (req.path.startsWith('/api')) return res.status(404).json({ error: 'not found' });
|
| 25 |
-
res.sendFile(path.join(webDist, 'index.html'));
|
| 26 |
-
});
|
| 27 |
|
| 28 |
const server = http.createServer(app);
|
| 29 |
const wss = new WebSocketServer({ server, path: '/ws' });
|
| 30 |
-
|
|
|
|
| 31 |
|
| 32 |
server.listen(PORT, () => console.log(`[dispatch] listening on :${PORT}`));
|
|
|
|
| 9 |
import Hub from './realtime.js';
|
| 10 |
|
| 11 |
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
| 12 |
+
const PORT = Number(process.env.PORT || 8080);
|
| 13 |
|
| 14 |
const app = express();
|
| 15 |
app.use(cors());
|
| 16 |
app.use(express.json());
|
| 17 |
+
app.use('/api', authRouter);
|
| 18 |
+
app.use('/api', requireAuth, routes);
|
|
|
|
| 19 |
|
| 20 |
const webDist = path.join(__dirname, '..', 'web', 'dist');
|
| 21 |
app.use(express.static(webDist));
|
| 22 |
+
app.get('*', (req, res) => res.sendFile(path.join(webDist, 'index.html')));
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
const server = http.createServer(app);
|
| 25 |
const wss = new WebSocketServer({ server, path: '/ws' });
|
| 26 |
+
const hub = new Hub(wss);
|
| 27 |
+
app.set('hub', hub);
|
| 28 |
|
| 29 |
server.listen(PORT, () => console.log(`[dispatch] listening on :${PORT}`));
|