-
-
Notifications
You must be signed in to change notification settings - Fork 16.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow flexible routing with SERVER_NAME config #2813
Comments
Then don't configure Please use Stack Overflow for questions about your own code. This tracker is for issues related to the project itself. Be sure to include a minimal, complete, and verifiable example. |
I had a feeling it was fixed as part of #998. The main issue stays the same – SERVER_NAME has implicit influence on routing, while some people use it only to control @davidism described a working solution on Stack Overflow. It involves dropping SERVER_NAME in favor of Would it make sense to add the following paragraph from the answer to the SERVER_NAME doc?
Docs for |
Docs PRs are welcome. We shouldn't be cramming routing docs into the config docs though. Either there's a better place in the Flask docs, or the http://werkzeug.palletsprojects.com/en/0.15.x/routing/ Werkzeug docs can be updated. |
#5634 in Flask 3.1 will further address this. |
Expected Behavior
Deployed a flask application which is reachable over multiple domains and ports:
client - Host: example.org -> LB -> flask app
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 likehttp://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 andurl_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 withHost: instance-1231.example.org
.Actual Behavior
Flasks creates the
werkzeug.routing.MapAdapter
withserver_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_adapter
and createMapAdapter
for request context withoutserver_name
parameter. Routing and URL generation works fine.The text was updated successfully, but these errors were encountered: