Fix root path routing - serve index.html for /
This commit is contained in:
38
server.js
38
server.js
@@ -47,25 +47,33 @@ app.use(session({
|
||||
}
|
||||
}));
|
||||
|
||||
// Serve static files first
|
||||
app.use(express.static('public'));
|
||||
|
||||
// Middleware to handle routes without .html extension
|
||||
app.use((req, res, next) => {
|
||||
if (req.path.indexOf('.') === -1 && !req.path.startsWith('/api/') && !req.path.startsWith('/admin/')) {
|
||||
const file = `${req.path}.html`;
|
||||
res.sendFile(path.join(__dirname, 'public', file), (err) => {
|
||||
if (err) next();
|
||||
});
|
||||
} else if (req.path.indexOf('.') === -1 && req.path.startsWith('/admin/') && req.path !== '/admin/') {
|
||||
const file = `${req.path}.html`;
|
||||
res.sendFile(path.join(__dirname, 'public', file), (err) => {
|
||||
if (err) next();
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
// Skip API routes
|
||||
if (req.path.startsWith('/api/')) {
|
||||
return next();
|
||||
}
|
||||
});
|
||||
|
||||
// Serve static files
|
||||
app.use(express.static('public'));
|
||||
// Handle root path
|
||||
if (req.path === '/') {
|
||||
return res.sendFile(path.join(__dirname, 'public', 'index.html'));
|
||||
}
|
||||
|
||||
// Handle paths without extensions (not already handled by static middleware)
|
||||
if (req.path.indexOf('.') === -1) {
|
||||
const file = `${req.path}.html`;
|
||||
return res.sendFile(path.join(__dirname, 'public', file), (err) => {
|
||||
if (err) {
|
||||
next();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
// Configure multer for file uploads (memory storage for CV uploads)
|
||||
const upload = multer({
|
||||
|
||||
Reference in New Issue
Block a user