import express from 'express'; import path from 'path'; import { fileURLToPath } from 'url'; import seoMiddleware from './seo-middleware.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const app = express(); const PORT = process.env.PORT || 3000; // CRITICAL: Apply SEO middleware FIRST (before static files) // This ensures HTML requests go through SEO middleware app.use(seoMiddleware); // Redirect /home to root app.use((req, res, next) => { if (req.path.startsWith('/home')) { const newPath = req.path.replace('/home', '') || '/'; return res.redirect(301, newPath); } next(); }); // Serve static files (CSS, JS, images) from dist folder app.use(express.static(path.join(__dirname, '../dist'))); app.listen(PORT, () => { console.log(`Server running on port ${PORT}`); console.log('Dynamic SEO enabled!'); }); export default app;