Fix MIME types using express.static options
This commit is contained in:
1 parent
61f29b2431
commit
b05efbaa34
1 file changed
+22
-12
+22
-12
@@ -14,16 +14,6 @@ const PORT = process.env.PORT || 3001;
|
|||||||
app.use(cors());
|
app.use(cors());
|
||||||
app.use(express.json());
|
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
|
// API Routes
|
||||||
|
|
||||||
// Get all groups
|
// Get all groups
|
||||||
@@ -383,8 +373,28 @@ app.post('/api/test-webhook', async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Serve React app
|
// Serve React app with proper MIME types
|
||||||
app.use(express.static(path.join(__dirname, '../client/build')));
|
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) => {
|
app.get('*', (req, res) => {
|
||||||
res.sendFile(path.join(__dirname, '../client/build/index.html'));
|
res.sendFile(path.join(__dirname, '../client/build/index.html'));
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user