Skip to content
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

vhost using blueprints with nonstandard port does not work as documented #1189

Closed
mashaalmemon opened this issue Apr 5, 2018 · 0 comments · Fixed by #2052
Closed

vhost using blueprints with nonstandard port does not work as documented #1189

mashaalmemon opened this issue Apr 5, 2018 · 0 comments · Fixed by #2052
Assignees
Milestone

Comments

@mashaalmemon
Copy link

I noticed that when I followed the example given in the sanic repo for vhosts here. Taking some exerpts from this example below, I modified my /etc/hosts file to point bp.example.com to 127.0.0.1 for testing.

I've shortened that example to illustrate the issue:

app = Sanic()
bp = Blueprint("bp", host="bp.example.com")

@bp.route("/question")
async def hello(request):
    return response.text("What is the meaning of life?")

@bp.route("/answer")
async def hello(request):
    return response.text("42")

app.blueprint(bp)

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=8000)

What I found was, this example didn't work. I was getting errors like this:

Error: Requested URL /answer not found

Digging deeper into the code, apparently the code is looking at the Host: header to decide if it has a route for a particular host. In the case of nonstandard ports (not 80 or 443), the Host: header has the ports appended. What would make this example work is changing one line:

bp = Blueprint("bp", host="bp.example.com:8000")

It is worth documenting this. A better fix might be perhaps added a port option to the Blueprint constructor when the port is non-standard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants