36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
const express = require('express');
|
|
const path = require('path');
|
|
const cors = require('cors');
|
|
|
|
const app = express();
|
|
const PORT = process.env.PORT || 3001;
|
|
|
|
// Enable CORS for all routes
|
|
app.use(cors());
|
|
|
|
// Serve static files from the build directory
|
|
app.use(express.static(path.join(__dirname, 'build')));
|
|
|
|
// Serve static files from the public directory (for test pages)
|
|
app.use(express.static(path.join(__dirname, 'public')));
|
|
|
|
// API proxy middleware (if needed)
|
|
app.use('/api', (req, res, next) => {
|
|
// Redirect API calls to the appropriate backend service
|
|
res.header('Access-Control-Allow-Origin', '*');
|
|
next();
|
|
});
|
|
|
|
// Handle React routing, return all requests to React app
|
|
app.get('*', (req, res) => {
|
|
res.sendFile(path.join(__dirname, 'build', 'index.html'));
|
|
});
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`🚀 Frontend server running on port ${PORT}`);
|
|
console.log(`📱 App: http://localhost:${PORT}`);
|
|
console.log(`🔨 Test: http://localhost:${PORT}/toommer-test.html`);
|
|
});
|
|
|
|
module.exports = app;
|