Skip to content

Commit

Permalink
Update path formatting and params usage for new express API
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hobinjk-ptc committed Sep 11, 2024
1 parent a6bce05 commit 708a575
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion libraries/LocalUIApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion libraries/serverHelpers/proxyRequestHandler.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions routers/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 708a575

Please sign in to comment.