Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2911 from markcor11/2827-GatekeeperRestart
Browse files Browse the repository at this point in the history
[0.12.0] Handle http-proxy exceptions when PFE is unavailable
  • Loading branch information
tobespc authored May 12, 2020
2 parents 0a1f789 + 76a588d commit 43356ec
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions src/gatekeeper/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,27 +158,42 @@ async function main() {
app.get("/api/pfe/ready", function (req, res) {
console.log(`/api/pfe/ready - req.originalUrl = ${req.originalUrl}`);
req.url = '/health';
proxy.web(req, res, {
target: pfe_target,
});
try {
proxy.web(req, res, {
target: pfe_target,
});
} catch (err) {
console.log("Proxy /api/pfe/ready error: ", err);
res.sendStatus(502);
}
});

/* PFE handles socket IO authentication*/
app.use('/socket.io/*', function (req, res) {
console.log(`/socket.io/* - req.originalUrl = ${req.originalUrl}`);
req.url = req.originalUrl;
proxy.web(req, res, {
target: pfe_target
});
try {
proxy.web(req, res, {
target: pfe_target
});
} catch (err) {
console.log("Proxy /socket.io/* error: ", err);
res.sendStatus(502);
}
});

/* Proxy Performance container routes */
app.use('*', authMiddleware, function (req, res) {
console.log(`* - req.originalUrl = ${req.originalUrl}`);
req.url = req.originalUrl;
proxy.web(req, res, {
target: pfe_target
});
try {
proxy.web(req, res, {
target: pfe_target
});
} catch (err) {
console.log("Proxy * error: ", err);
res.sendStatus(502);
}
});

const https = require('https');
Expand All @@ -189,7 +204,12 @@ async function main() {

server.on('upgrade', function (req, socket, head) {
console.log("Proxy: websocket connect 'upgrade'")
proxy.ws(req, socket, head);
try {
proxy.ws(req, socket, head);
} catch (err) {
console.log("Proxy upgrade error:", err);
res.sendStatus(502);
}
});

server.listen(port, () => console.log(`Gatekeeper listening on port ${port}!`))
Expand Down

0 comments on commit 43356ec

Please sign in to comment.