mirror of
https://github.com/SirBlobby/Hoya26.git
synced 2026-02-04 03:34:34 -05:00
Frontend Server Update
This commit is contained in:
26
frontend/server/index.js
Normal file
26
frontend/server/index.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import express from 'express';
|
||||
import compression from 'compression';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
// Enable gzip compression
|
||||
app.use(compression());
|
||||
|
||||
// Serve static files from the build directory (one level up from server folder)
|
||||
const buildPath = path.join(__dirname, '../build');
|
||||
app.use(express.static(buildPath));
|
||||
|
||||
// Handle SPA routing: serve index.html for any unknown routes
|
||||
app.get(/.*/, (req, res) => {
|
||||
res.sendFile(path.join(buildPath, 'index.html'));
|
||||
});
|
||||
|
||||
app.listen(PORT, '0.0.0.0', () => {
|
||||
console.log(`Server is running on http://localhost:${PORT}`);
|
||||
});
|
||||
Reference in New Issue
Block a user