feat(docker): Deploy frontend from express

This commit is contained in:
2025-05-29 15:54:19 +02:00
parent 98fdc290f4
commit 58fc2f7acf
3 changed files with 40 additions and 10 deletions

View File

@@ -3,11 +3,13 @@ const mysql = require('mysql2');
const cors = require('cors');
const { exec } = require('child_process');
const app = express();
const path = require('path');
const db = require('./db');
app.use(cors());
app.use(express.json());
const serveStatic = express.static(path.join(__dirname, '../frontend/dist'));
app.post('/api/login', (req, res) => {
const { username, password } = req.body;
@@ -83,4 +85,11 @@ app.get('/api/posts', (req, res) => {
});
});
app.use((req, res, next) => {
if (!req.path.startsWith('/api')) {
return serveStatic(req, res, next);
}
next();
});
app.listen(5000, () => console.log('Backend running on port 5000'));