diff --git a/server/src/server.ts b/server/src/server.ts index ceb64a6..698eb1a 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -6,15 +6,16 @@ import bodyParser from 'body-parser'; import { v4 as uuidv4 } from 'uuid'; import dotenv from 'dotenv'; import helmet from 'helmet'; +import path from 'path'; dotenv.config(); const app = express(); -const PORT = Number(process.env.PORT) || 3000; +const PORT = Number(process.env.PORT); // CORS configuration options const corsOptions = { - origin: process.env.CLIENT_URL || 'http://localhost:5173', + origin: process.env.CLIENT_URL, optionsSuccessStatus: 200, methods: ['GET', 'POST', 'DELETE'], allowedHeaders: ['Content-Type', 'Authorization'] @@ -34,9 +35,15 @@ app.use(cors(corsOptions)); app.use(bodyParser.json()); app.use(helmet()); app.use(limiter); +app.use('/', express.static(path.join(__dirname, '../static'))); + +// Navigate to the admin route in the client +app.get('*', (_req, res) => { + res.sendFile(path.resolve(__dirname, '../static', 'index.html')); +}); // Force HTTPS redirection in production -if(process.env.environment !== 'development') { +if(process.env.ENVIRONMENT !== 'development') { app.use((req, res, next) => { if (req.headers['x-forwarded-proto'] !== 'https') { return res.redirect(`https://${req.headers.host}${req.url}`); @@ -46,7 +53,7 @@ if(process.env.environment !== 'development') { } // Maximum number of party lines allowed -const MAX_PARTY_LINES = Number(process.env.MAX_PARTY_LINES) || 5; +const MAX_PARTY_LINES = Number(process.env.MAX_PARTY_LINES); // In-memory storage for party lines const partyLines = {}; @@ -194,7 +201,7 @@ app.post('/createPartyLine', [ // Create a new party line partyLines[currentPartyLine] = { clients: [], - lastEvent: process.env.INITIAL_RUMOR || '...nothing has been said, yet.', + lastEvent: process.env.INITIAL_RUMOR, lastActivity: Date.now() };