web: frontend: Switch to express

This commit is contained in:
2025-11-11 15:19:34 -06:00
parent 4c34931b34
commit 6c57e960aa
2 changed files with 38 additions and 2 deletions

View File

@@ -1,6 +1,16 @@
FROM node:18-alpine
# Build Stage
FROM node:18-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm", "start"]
RUN npm run build
# Production Stage
FROM node:18-alpine AS production
WORKDIR /app
COPY --from=build /app/build ./build
COPY server.js ./
RUN npm install --production express
EXPOSE 3000
CMD ["node", "server.js"]

26
web/frontend/server.js Normal file
View File

@@ -0,0 +1,26 @@
const express = require('express');
const path = require('path');
const app = express();
const PORT = process.env.PORT || 3000;
// Serve static files from the build directory
app.use(express.static(path.join(__dirname, 'build')));
// Handle client-side routing - serve index.html for all routes
app.get('/*splat', (req, res) => {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
const server = app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
// Graceful shutdown on CTRL+C
process.on('SIGINT', () => {
console.log('\nShutting down gracefully...');
server.close(() => {
console.log('Server closed');
process.exit(0);
});
});