mirror of
https://github.com/ANL-CEEESA/UnitCommitment.jl.git
synced 2025-12-06 00:08:52 -06:00
web: frontend: Switch to express
This commit is contained in:
@@ -1,6 +1,16 @@
|
|||||||
FROM node:18-alpine
|
# Build Stage
|
||||||
|
FROM node:18-alpine AS build
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm install
|
RUN npm install
|
||||||
COPY . .
|
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
26
web/frontend/server.js
Normal 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);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user