Fix MIME types using express.static options

This commit is contained in:
nmemmert committed 2025-12-10 16:17:19 -05:00
1 parent 61f29b2431
commit b05efbaa34
1 file changed
+22 -12
+22 -12
View File
@@ -14,16 +14,6 @@ const PORT = process.env.PORT || 3001;
app.use(cors());
app.use(express.json());
// Set correct MIME types for static files
app.use((req, res, next) => {
if (req.url.endsWith('.js')) {
res.setHeader('Content-Type', 'application/javascript');
} else if (req.url.endsWith('.css')) {
res.setHeader('Content-Type', 'text/css');
}
next();
});
// API Routes
// Get all groups
@@ -383,8 +373,28 @@ app.post('/api/test-webhook', async (req, res) => {
}
});
// Serve React app
app.use(express.static(path.join(__dirname, '../client/build')));
// Serve React app with proper MIME types
const mimeTypes = {
'.js': 'application/javascript',
'.css': 'text/css',
'.json': 'application/json',
'.png': 'image/png',
'.jpg': 'image/jpeg',
'.gif': 'image/gif',
'.svg': 'image/svg+xml',
'.woff': 'font/woff',
'.woff2': 'font/woff2'
};
app.use(express.static(path.join(__dirname, '../client/build'), {
setHeaders: (res, filePath) => {
const ext = path.extname(filePath).toLowerCase();
if (mimeTypes[ext]) {
res.setHeader('Content-Type', mimeTypes[ext]);
}
}
}));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '../client/build/index.html'));
});