You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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 pointbp.example.com
to127.0.0.1
for testing.I've shortened that example to illustrate the issue:
What I found was, this example didn't work. I was getting errors like this:
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), theHost:
header has the ports appended. What would make this example work is changing one line: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.The text was updated successfully, but these errors were encountered: