← back to Beverlyhillsvideos
server.js
17 lines
const express = require('express');
const path = require('node:path');
const app = express();
const PORT = process.env.PORT || 9941;
const PUB = path.join(__dirname, 'public');
app.get('/ads.txt', (_req, res) => res.type('text/plain').send('google.com, pub-5278231299883833, DIRECT, f08c47fec0942fa0\n'));
app.get('/robots.txt', (_req, res) => res.type('text/plain').send('User-agent: *\nAllow: /\nSitemap: https://beverlyhillsvideos.com/sitemap.xml\n'));
app.get('/sitemap.xml', (_req, res) => {
const fs = require('node:fs');
const walk = dir => fs.readdirSync(dir, { withFileTypes: true }).flatMap(e => e.isDirectory() ? walk(path.join(dir, e.name)) : e.name.endsWith('.html') ? [path.join(dir, e.name)] : []);
const urls = walk(PUB).map(f => '/' + path.relative(PUB, f).replaceAll(path.sep, '/').replace(/index\.html$/, '').replace(/\.html$/, ''));
res.type('application/xml').send(`<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">${urls.map(u => `<url><loc>https://beverlyhillsvideos.com${u}</loc></url>`).join('')}</urlset>`);
});
app.get('/healthz', (_req, res) => res.json({ ok: true, site: 'beverlyhillsvideos' }));
app.use(express.static(PUB, { extensions: ['html'] }));
app.listen(PORT, () => console.log(`beverlyhillsvideos on :${PORT}`));