Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Fix #2734, make protocol configurable with EXPECT_PROTOCOL=https (#2864)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianb authored and jaredhirsch committed May 23, 2017
1 parent 3d10b62 commit a9761b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions server/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ var conf = convict({
env: "CONTENT_ORIGIN",
arg: "contentOrigin"
},
expectProtocol: {
doc: "Treat all incoming requests as using this protocol, instead of defaulting to http: or detecting from X-Forwarded-Proto",
format: String,
default: "",
env: "EXPECT_PROTOCOL",
arg: "expectProtocol"
},
localhostSsl: {
doc: "Turn on SSL on localhost, using ~/.localhost-ssl/*",
format: Boolean,
Expand Down
10 changes: 10 additions & 0 deletions server/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ function addHSTS(req, res) {

addRavenRequestHandler(app);

if (config.expectProtocol) {
if (!/^https?$/.test(config.expectProtocol)) {
throw new Error(`Error, bad EXPECT_PROTOCOL: ${config.expectProtocol}`);
}
app.use((req, res, next) => {
req.headers["x-forwarded-proto"] = config.expectProtocol;
next();
});
}

app.use((req, res, next) => {
genUuid.generate(genUuid.V_RANDOM, function(err, uuid) {
if (!err) {
Expand Down

0 comments on commit a9761b6

Please sign in to comment.