-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.py
37 lines (31 loc) · 947 Bytes
/
web.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from sanic_jinja2 import SanicJinja2
from helpers import routinghelper
import asyncio
import jinja2
import sanic
app = sanic.Sanic("Portfolio")
app.config.USE_UVLOOP = False
app.ctx.jinja = SanicJinja2(
app,
loader=jinja2.FileSystemLoader("./assets/html"),
pkg_path="assets/html",
extensions=["jinja2.ext.loopcontrols"],
enable_async=True
)
routinghelper.add_all_routes(app)
app.static("assets", "assets", name="assets")
async def main() -> None:
"""
Start the server in a development/nonprod environment.
"""
server = await app.create_server(host="localhost", port=8500, debug=True, return_asyncio_server=True)
await server.startup()
await server.after_start()
await server.serve_forever()
if __name__ == "__main__":
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
loop.run_until_complete(main())
except KeyboardInterrupt:
print("Exiting...")