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
Support mounting application elsewhere than at root path #1731
Comments
I like this idea. |
This seems like a fairly easy one to add. |
Related discussion: https://community.sanicframework.org/t/sanic-app-on-nginx-subpath/463 |
I finally got back to testing this. I ran the following on:
On all of these branches, this seemed to work fine. from sanic import Sanic
from sanic.response import text
app = Sanic("app")
app.config.SERVER_NAME = "example.com/api"
@app.route("/foo")
def handler(request):
url = app.url_for("handler", _external=True)
return text(f"URL: {url}") The result:
Am I missing something? Can we close this? |
Yep, that's right. I deploy sanic using that same pattern at my workplace in several applications. |
Marking as a documentation issue. |
Looking at sanic-org/sanic#1731 this is “a documentation issue”.
Sanic app might be exposed publicly in a path other than root at a HTTP server that also serves other things on the same domain. E.g.
https://company.com/blog/
is proxied to Sanic app athttp://localhost:8000/
.Currently Sanic offers no support for that, with
url_for
resolving to absolute paths pointing at site root.It would be good to add support e.g. via
config.SERVER_NAME
that also included the external root path, so that proper URLs would be formed whenever external URLs are requested. The path information is already available but not used if presented on proxy headersreq.forwarded
, whereas I am not exactly sure ofSERVER_NAME
handling.The text was updated successfully, but these errors were encountered: