Fix: warning

* Fix: missing else,
* move out to function already taken path comparison
master
Mészáros Mihály 2020-01-02 15:49:32 +01:00
parent c0b6ff6be4
commit 6e7f6b4a0d
1 changed files with 33 additions and 7 deletions

View File

@ -386,24 +386,31 @@ async function runHttpsServer()
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)
{
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);
res.redirect(ltiURL);
}
else
return next();
}
else
res.redirect(`https://${req.hostname}${req.url}`);
});
// Serve all files in the public folder as static files.
@ -420,6 +427,25 @@ async function runHttpsServer()
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.
*/