From 708a5752e610340360c9549831037d0b6fb78340 Mon Sep 17 00:00:00 2001 From: James Hobin Date: Wed, 11 Sep 2024 16:01:23 -0400 Subject: [PATCH] Update path formatting and params usage for new express API Notably instead of params[0] from '*' being https://asdf/fdsa it will now be params.proxyPath from '*proxyPath' being `['https:', '', 'asdf', fdsa']` so this updates with a small use of `.join` and addition of wildcard names --- libraries/LocalUIApp.js | 2 +- libraries/serverHelpers/proxyRequestHandler.js | 2 +- routers/object.js | 4 ++-- server.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/LocalUIApp.js b/libraries/LocalUIApp.js index 72f05da10..3890144f6 100644 --- a/libraries/LocalUIApp.js +++ b/libraries/LocalUIApp.js @@ -63,7 +63,7 @@ class LocalUIApp { } res.status(403).send('access prohibited to non-script non-style file'); }); - this.app.get('/proxy/*', proxyRequestHandler); + this.app.get('/proxy/*proxyPath', proxyRequestHandler); if (this.userinterfacePath && fs.existsSync(this.userinterfacePath)) { this.app.use(express.static(this.userinterfacePath)); } else { diff --git a/libraries/serverHelpers/proxyRequestHandler.js b/libraries/serverHelpers/proxyRequestHandler.js index 36a869fe8..77d256ff3 100644 --- a/libraries/serverHelpers/proxyRequestHandler.js +++ b/libraries/serverHelpers/proxyRequestHandler.js @@ -1,7 +1,7 @@ const https = require('https'); const proxyRequestHandler = (req, res) => { - const input = req.params[0]; + const input = req.params.proxyPath.join('/'); if (!input.includes('://')) { const proxyURL = `https://spatial.ptc.io/${req.params[0]}`; const headers = req.headers; diff --git a/routers/object.js b/routers/object.js index 88b457cfd..4734657e7 100644 --- a/routers/object.js +++ b/routers/object.js @@ -426,13 +426,13 @@ router.post('/:objectName/frame/:frameName/pinned/', function (req, res) { }); // Check the existence of a file at a filepath within the .identity directory of the specified object -router.get('/:objectName/checkFileExists/*', async (req, res) => { +router.get('/:objectName/checkFileExists/*filePath', async (req, res) => { if (!utilities.isValidId(req.params.objectName)) { res.status(400).send('Invalid object name. Must be alphanumeric.'); return; } // Extract the file path from the URL - const filePath = req.params[0]; + const filePath = req.params.filePath.join('/'); objectController.checkFileExists(req.params.objectName, filePath).then(exists => { res.json({ exists: exists }); }).catch(e => { diff --git a/server.js b/server.js index ef6019ef4..65299f041 100644 --- a/server.js +++ b/server.js @@ -2216,7 +2216,7 @@ function objectWebServer() { // Proxies requests to spatial.ptc.io, for CORS video playback const proxyRequestHandler = require('./libraries/serverHelpers/proxyRequestHandler.js'); - webServer.get('/proxy/*', proxyRequestHandler); + webServer.get('/proxy/*proxyPath', proxyRequestHandler); const {oauthRefreshRequestHandler, oauthAcquireRequestHandler} = require('./libraries/serverHelpers/oauthRequestHandlers.js'); webServer.post('/oauthRefresh', oauthRefreshRequestHandler);