-
-
Notifications
You must be signed in to change notification settings - Fork 16.5k
Description
Expected Behavior
Deployed a flask application which is reachable over multiple domains and ports:
- external via load balancer:
client - Host: example.org -> LB -> flask app
- internal via DNS service discovery without load balancer:
client - Host: instance-1231.example.org -> flask app
If the client connects directly (Host: instance-1231.example.org
) the app should be able to return absolute and stable URLs like http://example.org/path/to/my/view
as the URL (http://instance-1231.example.org/path/to/my/view
) with the internal DNS name is ephemeral.
Therefore I configured the SERVER_NAME
config key and url_for
generates the intended absolute URL by using _external=True
within and without request context. But the app should be still able to route requests coming with Host: instance-1231.example.org
.
Actual Behavior
Flasks creates the werkzeug.routing.MapAdapter
with server_name=app.config['SERVER_NAME']
and therefore no view method will match to incoming requests with Host: instance-1231.example.org
.
Environment
- Python version: 2.7.13 (I'm sorry)
- Flask version: 1.0.2
- Werkzeug version: 0.14.1
Applied workaround:
Overwrite Flask.create_url_adapter
and create MapAdapter
for request context without server_name
parameter. Routing and URL generation works fine.