We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 10e00b6 commit bec30b2Copy full SHA for bec30b2
1 file changed
service/src/express.js
@@ -14,8 +14,19 @@ const express = require("express")
14
15
const app = express();
16
app.use(function(req, res, next) {
17
- req.getRoot = function() {
18
- return req.protocol + "://" + req.get('host');
+ req.getRoot = function () {
+ const port = Number(req.headers['x-forwarded-port'] || req.socket.localPort);
19
+ const protocol = req.protocol;
20
+ const hostname = req.hostname;
21
+ let includePort = false;
22
+
23
+ // Only include port if non-standard for protocol
24
+ if ((protocol === 'http' && port !== 80) ||
25
+ (protocol === 'https' && port !== 443)) {
26
+ includePort = true;
27
+ }
28
29
+ return protocol + '://' + hostname + (includePort ? (':' + port) : '');
30
};
31
32
req.getPath = function() {
0 commit comments