Implement request handling for 3D models in app.js
- Added middleware to prevent direct access to /models/ paths, directing users to use /api/models/ instead for optimized 3D models. - Updated comments to clarify the purpose of the new middleware and its role in serving models through the API.
This commit is contained in:
@@ -80,7 +80,14 @@ app.use('/api/blog', blogRouter);
|
|||||||
app.use('/api/termine', termineRouter);
|
app.use('/api/termine', termineRouter);
|
||||||
|
|
||||||
// Serve frontend SPA for non-API routes to support history mode clean URLs
|
// Serve frontend SPA for non-API routes to support history mode clean URLs
|
||||||
|
// /models/* nicht statisch ausliefern – nur über /api/models (Proxy mit Komprimierung)
|
||||||
const frontendDir = path.join(__dirname, '../frontend');
|
const frontendDir = path.join(__dirname, '../frontend');
|
||||||
|
app.use((req, res, next) => {
|
||||||
|
if (req.path.startsWith('/models/')) {
|
||||||
|
return res.status(404).send('Use /api/models/ for 3D models (optimized).');
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
app.use(express.static(path.join(frontendDir, 'dist')));
|
app.use(express.static(path.join(frontendDir, 'dist')));
|
||||||
app.get(/^\/(?!api\/).*/, (req, res) => {
|
app.get(/^\/(?!api\/).*/, (req, res) => {
|
||||||
res.sendFile(path.join(frontendDir, 'dist', 'index.html'));
|
res.sendFile(path.join(frontendDir, 'dist', 'index.html'));
|
||||||
|
|||||||
Reference in New Issue
Block a user