-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
43 lines (28 loc) · 833 Bytes
/
test.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
38
39
40
41
42
43
# test.py
import time
import threading
from fastapi import FastAPI
from auto_fastapi import Method, AutoFastAPI, Builder, Server, Config
def startup() -> None:
print("startup")
def login(username: str, password: str) -> dict[str, str | dict[str, str]]:
return {
"response": "success",
"request": dict(username=username, password=password)
}
TIMEOUT = 0
def main() -> None:
app = FastAPI()
AutoFastAPI().push_all(
app,
[
(startup, Builder.event("startup")),
(login, Builder.endpoint("/login", [Method.GET]))
]
)
server = Server(Config(app, host="127.0.0.1", port=5555))
if TIMEOUT:
threading.Thread(target=lambda: (time.sleep(TIMEOUT), server.exit())).start()
server.run()
if __name__ == '__main__':
main()