2018-07-11 09:42:34 +01:00
|
|
|
from sanic import Blueprint, Sanic
|
|
|
|
from sanic.response import file, json
|
2016-10-15 20:38:12 +01:00
|
|
|
|
|
|
|
app = Sanic(__name__)
|
|
|
|
blueprint = Blueprint('name', url_prefix='/my_blueprint')
|
2017-05-19 09:26:56 +01:00
|
|
|
blueprint2 = Blueprint('name2', url_prefix='/my_blueprint2')
|
|
|
|
blueprint3 = Blueprint('name3', url_prefix='/my_blueprint3')
|
2016-10-15 20:38:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route('/foo')
|
|
|
|
async def foo(request):
|
|
|
|
return json({'msg': 'hi from blueprint'})
|
|
|
|
|
|
|
|
|
|
|
|
@blueprint2.route('/foo')
|
|
|
|
async def foo2(request):
|
|
|
|
return json({'msg': 'hi from blueprint2'})
|
|
|
|
|
2017-05-19 09:26:56 +01:00
|
|
|
|
2018-07-11 09:42:34 +01:00
|
|
|
@blueprint3.route('/foo')
|
|
|
|
async def index(request):
|
|
|
|
return await file('websocket.html')
|
|
|
|
|
|
|
|
|
|
|
|
@app.websocket('/feed')
|
2017-03-09 10:33:34 +00:00
|
|
|
async def foo3(request, ws):
|
|
|
|
while True:
|
|
|
|
data = 'hello!'
|
|
|
|
print('Sending: ' + data)
|
|
|
|
await ws.send(data)
|
|
|
|
data = await ws.recv()
|
|
|
|
print('Received: ' + data)
|
2016-10-15 20:38:12 +01:00
|
|
|
|
2017-03-09 10:31:19 +00:00
|
|
|
app.blueprint(blueprint)
|
|
|
|
app.blueprint(blueprint2)
|
2017-03-09 10:33:34 +00:00
|
|
|
app.blueprint(blueprint3)
|
2016-10-15 20:38:12 +01:00
|
|
|
|
|
|
|
app.run(host="0.0.0.0", port=8000, debug=True)
|