← back to Beverlyhillsbutler
server.js
34 lines
const express = require('express');
const path = require('path');
const app = express();
const PORT = process.env.PORT || 9906;
// No-cache for HTML so Cloudflare doesn't stale it
app.use((req, res, next) => {
if (req.path.match(/\.(html|htm)$/) || req.path === '/') {
res.setHeader('Cache-Control', 'no-store, must-revalidate');
}
next();
});
// 404-guard: never serve snapshot/backup files even if one lands in public/
app.use((req, res, next) => {
if (/\.(bak)(\..*)?$|\.pre-/i.test(req.path)) {
return res.status(404).send('Not found');
}
next();
});
app.use(express.static(path.join(__dirname, 'public')));
app.get('/health', (req, res) => res.json({ status: 'ok', site: 'beverlyhillsbutler.com' }));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
app.listen(PORT, () => {
console.log(`beverlyhillsbutler.com running on :${PORT}`);
});