2017-01-23 19:58:37 -08:00
|
|
|
import asyncio
|
2021-11-23 23:00:25 +02:00
|
|
|
|
2017-02-04 15:27:46 +08:00
|
|
|
import uvloop
|
2017-01-23 19:58:37 -08:00
|
|
|
|
2021-11-23 23:00:25 +02:00
|
|
|
from sanic import Sanic, response
|
|
|
|
|
|
|
|
|
2021-12-24 00:30:27 +02:00
|
|
|
app = Sanic("Example")
|
2017-01-23 19:58:37 -08:00
|
|
|
|
2017-06-01 11:53:05 -07:00
|
|
|
|
2017-01-23 19:58:37 -08:00
|
|
|
@app.route("/")
|
|
|
|
async def test(request):
|
2017-04-06 14:39:54 -04:00
|
|
|
return response.json({"answer": "42"})
|
2017-01-23 19:58:37 -08:00
|
|
|
|
2021-11-23 23:00:25 +02:00
|
|
|
|
2021-12-13 09:36:41 +02:00
|
|
|
async def main():
|
|
|
|
server = await app.create_server(
|
|
|
|
port=8000, host="0.0.0.0", return_asyncio_server=True
|
|
|
|
)
|
|
|
|
|
|
|
|
if server is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
await server.startup()
|
|
|
|
await server.serve_forever()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
asyncio.set_event_loop(uvloop.new_event_loop())
|
|
|
|
asyncio.run(main())
|