-
Notifications
You must be signed in to change notification settings - Fork 12
/
webapi.py
37 lines (27 loc) · 951 Bytes
/
webapi.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
import uvicorn
from fastapi import FastAPI
from src import HOST, PORT, VERSION
from src.interfaces import BaseUI
from src.interfaces.webapi import BaseAPI, BaseRouter, SolverRouter
class WebAPI(BaseUI):
"""Web API"""
def __init__(self) -> None:
super().__init__()
self.init()
self.app: BaseAPI = BaseAPI(version=VERSION)
self.api: FastAPI = self.app.api
self.webconfig: uvicorn.Config = uvicorn.Config(
app = self.api,
host = HOST,
port = PORT,
log_level = "info"
)
self.server: uvicorn.Server = uvicorn.Server(config=self.webconfig)
self.solver: BaseRouter = SolverRouter(self, tags={"spellsolver": "true"})
self.api.include_router(self.solver.router)
def mainloop(self) -> None:
"""Mainloop of the WebAPI"""
self.server.run()
if __name__ == "__main__":
app = WebAPI()
app.mainloop()