From 62218179003536fa163cfe743f478b7c6ea5af95 Mon Sep 17 00:00:00 2001 From: AI Bot Date: Wed, 2 Sep 2026 16:02:22 +0530 Subject: [PATCH] Proxy Meshy GLB download through backend to bypass CORS --- backend/server.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/backend/server.js b/backend/server.js index c918fc7..be42a51 100644 --- a/backend/server.js +++ b/backend/server.js @@ -531,7 +531,32 @@ app.get('/api/sparkplug/status-3d/:taskId', authenticate, async (req, res) => { } }); - res.json(response.data); + const data = response.data; + + // If generation succeeded, intercept and proxy download the model to local storage to bypass CORS + if (data.status === 'SUCCEEDED' && data.model_urls && data.model_urls.glb) { + const glbUrl = data.model_urls.glb; + const localFilename = `${taskId}.glb`; + const localFilepath = path.join(uploadsDir, localFilename); + + // Only download if we haven't already + if (!fs.existsSync(localFilepath)) { + try { + const fileRes = await axios.get(glbUrl, { responseType: 'arraybuffer' }); + fs.writeFileSync(localFilepath, fileRes.data); + } catch (downloadErr) { + console.error("Failed to proxy download Meshy GLB:", downloadErr); + } + } + + if (fs.existsSync(localFilepath)) { + // Overwrite the returned url with our local proxy url + const serverUrl = `${req.protocol}://${req.get('host')}`; + data.model_urls.glb = `${serverUrl}/uploads/${localFilename}`; + } + } + + res.json(data); } catch (err) { const errorMsg = err.response?.data?.message || err.message; res.status(500).json({ error: errorMsg });