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.
Expected Behavior
Deployed a flask application which is reachable over multiple domains and ports:
client - Host: example.org -> LB -> flask appclient - Host: instance-1231.example.org -> flask appIf the client connects directly (
Host: instance-1231.example.org) the app should be able to return absolute and stable URLs likehttp://example.org/path/to/my/viewas the URL (http://instance-1231.example.org/path/to/my/view) with the internal DNS name is ephemeral.Therefore I configured the
SERVER_NAMEconfig key andurl_forgenerates the intended absolute URL by using_external=Truewithin and without request context. But the app should be still able to route requests coming withHost: instance-1231.example.org.Actual Behavior
Flasks creates the
werkzeug.routing.MapAdapterwithserver_name=app.config['SERVER_NAME']and therefore no view method will match to incoming requests withHost: instance-1231.example.org.Environment
Applied workaround:
Overwrite
Flask.create_url_adapterand createMapAdapterfor request context withoutserver_nameparameter. Routing and URL generation works fine.