add support for virtual hosts

This commit is contained in:
Raphael Deem
2017-01-08 15:48:12 -08:00
parent b0bf989056
commit 4f832ac9af
4 changed files with 71 additions and 10 deletions

18
examples/vhosts.py Normal file
View File

@@ -0,0 +1,18 @@
from sanic.response import text
from sanic import Sanic
# Usage
# curl -H "Host: example.com" localhost:8000
# curl -H "Host: sub.example.com" localhost:8000
app = Sanic()
@app.route('/', host="example.com")
async def hello(request):
return text("Answer")
@app.route('/', host="sub.example.com")
async def hello(request):
return text("42")
if __name__ == '__main__':
app.run(host="0.0.0.0", port=8000)