36 lines
1.1 KiB
Plaintext
36 lines
1.1 KiB
Plaintext
|
|
import express from 'express';
|
||
|
|
import path from 'path';
|
||
|
|
import { fileURLToPath } from 'url';
|
||
|
|
import seoMiddleware from './server/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);
|
||
|
|
|
||
|
|
// Serve static files - BUT middleware handles ALL HTML requests
|
||
|
|
// Static files only serve: CSS, JS, images, fonts - NOT HTML
|
||
|
|
app.use((req, res, next) => {
|
||
|
|
// If it's an HTML request (no extension or ends with .html), let middleware handle it
|
||
|
|
if (!req.path.match(/\.[a-z]{2,4}$/i) || req.path.endsWith('.html')) {
|
||
|
|
return next(); // Let SEO middleware handle it
|
||
|
|
}
|
||
|
|
// For non-HTML files, serve them
|
||
|
|
next();
|
||
|
|
});
|
||
|
|
|
||
|
|
app.use(express.static(__dirname, { index: false }));
|
||
|
|
app.use('/home', express.static(__dirname, { index: false }));
|
||
|
|
|
||
|
|
app.listen(PORT, () => {
|
||
|
|
console.log(`Server running on port ${PORT}`);
|
||
|
|
console.log('Dynamic SEO enabled!');
|
||
|
|
});
|
||
|
|
|
||
|
|
export default app;
|