fix: use npm install in Dockerfile, add static file serving
- Dockerfile uses npm install (no lockfile yet, kaniko builds in-cluster) - Server serves client build from ./public in production - SPA fallback for client-side routing
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import express from 'express';
|
||||
import cors from 'cors';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { createServer } from 'http';
|
||||
import { config } from './config.js';
|
||||
import { closeDb } from './db/index.js';
|
||||
@@ -10,6 +12,8 @@ import authRoutes from './routes/auth.js';
|
||||
import connectionsRoutes from './routes/connections.js';
|
||||
import messagesRoutes from './routes/messages.js';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(cors({ origin: config.CORS_ORIGIN, credentials: true }));
|
||||
@@ -23,6 +27,16 @@ app.use('/api/auth', authRoutes);
|
||||
app.use('/api/connections', connectionsRoutes);
|
||||
app.use('/api/messages', messagesRoutes);
|
||||
|
||||
// Serve static frontend in production
|
||||
const publicPath = path.resolve(__dirname, '../public');
|
||||
app.use(express.static(publicPath));
|
||||
app.get('*', (_req, res, next) => {
|
||||
if (_req.path.startsWith('/api') || _req.path.startsWith('/ws')) {
|
||||
return next();
|
||||
}
|
||||
res.sendFile(path.join(publicPath, 'index.html'));
|
||||
});
|
||||
|
||||
const server = createServer(app);
|
||||
|
||||
createWebSocketServer(server);
|
||||
|
||||
Reference in New Issue
Block a user