2

I'm trying to auto-redirect users of my site to https, but in order to do so I need to know if they're already visiting via https, otherwise I'll get into an infinite redirect loop.

From searching, I've tried looking at these values

console.log('!!!!!!!!!ROUTING TO REDUX!!!!!!!!', request.secure, request.protocol, request.get('X-Forwarded-Protocol'));

But I'm seeing this get logged

2017-06-23T07:20:10.996750+00:00 app[web.1]: !!!!!!!!!ROUTING TO REDUX!!!!!!!! false http undefined

2017-06-23T07:20:11.028280+00:00 heroku[router]: at=info method=GET path="/" host=my-library-io.herokuapp.com request_id=3fc84fae-02bd-443a-8265-c45def605ba1 fwd="64.134.226.42" dyno=web.1 connect=0ms service=33ms status=200 bytes=2309 protocol=https

even when viewing https.

The site is here https://mylibrary.io/ The original Heroku url is here https://my-library-io.herokuapp.com/

Both URLs load, and show as secure in my browser, but both also appear to log as https, via the second entry above; but with either I can't look at anything in the request object to surmise that I'm viewing via https.

Community
  • 1
  • 1
Adam Rackis
  • 82,527
  • 56
  • 270
  • 393

1 Answers1

1

Use request.get('X-Forwarded-Proto'), as opposed to X-Forwarded-Protocol. As you can see, it is used by the npm package heroku-ssl-redirect. This de-facto standard HTTP header is also documented on Wikipedia.

Patrick Roberts
  • 49,224
  • 10
  • 102
  • 153