Fix: warning
* Fix: missing else, * move out to function already taken path comparisonmaster
parent
c0b6ff6be4
commit
6e7f6b4a0d
|
|
@ -386,24 +386,31 @@ async function runHttpsServer()
|
||||||
|
|
||||||
app.use('/.well-known/acme-challenge', express.static('public/.well-known/acme-challenge'));
|
app.use('/.well-known/acme-challenge', express.static('public/.well-known/acme-challenge'));
|
||||||
|
|
||||||
app.all('*', (req, res, next) =>
|
app.all('*', async (req, res, next) =>
|
||||||
{
|
{
|
||||||
if (req.secure)
|
if (req.secure)
|
||||||
{
|
{
|
||||||
const ltiURL = new URL(req.protocol + '://' + req.get('host') + req.originalUrl);
|
const ltiURL = new URL(`${req.protocol }://${ req.get('host') }${req.originalUrl}`);
|
||||||
|
|
||||||
if (req.isAuthenticated && req.user && req.user.displayName && !ltiURL.searchParams.get('displayName'))
|
if (
|
||||||
|
req.isAuthenticated &&
|
||||||
|
req.user &&
|
||||||
|
req.user.displayName &&
|
||||||
|
!ltiURL.searchParams.get('displayName') &&
|
||||||
|
!is_path_already_taken(req.url)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
ltiURL.searchParams.append('displayName', req.user.displayName);
|
ltiURL.searchParams.append('displayName', req.user.displayName);
|
||||||
|
|
||||||
res.redirect(ltiURL);
|
res.redirect(ltiURL);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
res.redirect(`https://${req.hostname}${req.url}`);
|
||||||
|
|
||||||
res.redirect(`https://${req.hostname}${req.url}`);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Serve all files in the public folder as static files.
|
// Serve all files in the public folder as static files.
|
||||||
|
|
@ -420,6 +427,25 @@ async function runHttpsServer()
|
||||||
httpServer.listen(config.listeningRedirectPort);
|
httpServer.listen(config.listeningRedirectPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function is_path_already_taken(url) {
|
||||||
|
const alreadyTakenPath =
|
||||||
|
[
|
||||||
|
'/config/',
|
||||||
|
'/static/',
|
||||||
|
'/images/',
|
||||||
|
'/sounds/',
|
||||||
|
'/favicon.',
|
||||||
|
'/auth/'
|
||||||
|
];
|
||||||
|
|
||||||
|
alreadyTakenPath.forEach((path) => {
|
||||||
|
if (url.toString().startsWith(path))
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a WebSocketServer to allow WebSocket connections from browsers.
|
* Create a WebSocketServer to allow WebSocket connections from browsers.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue