2017-01-24 03:58:37 +00:00
|
|
|
import asyncio
|
2021-11-23 21:00:25 +00:00
|
|
|
|
2017-02-04 07:27:46 +00:00
|
|
|
import uvloop
|
2017-01-24 03:58:37 +00:00
|
|
|
|
2021-11-23 21:00:25 +00:00
|
|
|
from sanic import Sanic, response
|
|
|
|
|
2021-12-23 22:30:27 +00:00
|
|
|
app = Sanic("Example")
|
2017-01-24 03:58:37 +00:00
|
|
|
|
2017-06-01 19:53:05 +01:00
|
|
|
|
2017-01-24 03:58:37 +00:00
|
|
|
@app.route("/")
|
|
|
|
async def test(request):
|
2017-04-06 19:39:54 +01:00
|
|
|
return response.json({"answer": "42"})
|
2017-01-24 03:58:37 +00:00
|
|
|
|
2021-11-23 21:00:25 +00:00
|
|
|
|
2021-12-13 07:36:41 +00: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())
|