So I spent far too much time debugging why my session were expiring rapidly on Mighty Spring's stage server that runs on Heroku. I finally dug deep enough with logging to find that
remote_addr was returning a different value each time. I created a new
Request class that returns the correct
remote_addr when running on Heroku.
from flask import Request
`Request` subclass that overrides `remote_addr` with Heroku's
HTTP_X_FORWARDED_FOR when available.
"""The remote address of the client."""
fwd = self.environ.get('HTTP_X_FORWARDED_FOR', None)
if fwd is None:
# sometimes x-forwarded-for contains multiple addresses,
# actual client is first, rest are proxy
fwd = fwd.split(',')
## use HerokuRequest class so we get real IPs
app.request_class = HerokuRequest