feat(docker): Deploy frontend from express
This commit is contained in:
@@ -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'));
|
||||
|
||||
Reference in New Issue
Block a user