fix: Add backend proxy for GLB files to resolve CORS in ImageTo3DModal
Build and Deploy / build-and-push (push) Successful in 27s
Build and Deploy / build-and-push (push) Successful in 27s
This commit is contained in:
@@ -246,6 +246,22 @@ app.post('/api/users/deduct-credit', authenticate, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// 9.5 Proxy for downloading GLB files to fix CORS issues in frontend viewers
|
||||
app.get('/api/proxy/glb', async (req, res) => {
|
||||
const { url } = req.query;
|
||||
if (!url) return res.status(400).json({ error: 'URL required' });
|
||||
try {
|
||||
const response = await axios.get(url, { responseType: 'stream' });
|
||||
res.setHeader('Content-Type', 'model/gltf-binary');
|
||||
// Add CORS headers for the frontend to easily fetch it
|
||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||
response.data.pipe(res);
|
||||
} catch (err) {
|
||||
console.error('Proxy error:', err.message);
|
||||
res.status(500).json({ error: 'Failed to proxy file' });
|
||||
}
|
||||
});
|
||||
|
||||
// 10. Upload file
|
||||
app.post('/api/upload', authenticate, upload.single('file'), (req, res) => {
|
||||
if (!req.file) return res.status(400).json({ error: 'No file uploaded' });
|
||||
|
||||
Reference in New Issue
Block a user