-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
46 lines (33 loc) · 1.01 KB
/
main.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
44
45
46
import os
from fastapi import FastAPI, Request
app = FastAPI()
REQUEST_FILE = "api_requests/requests.txt"
def check_file():
if not os.path.isfile(REQUEST_FILE):
with open(REQUEST_FILE, "w"):
pass
async def write_request(request: Request):
if await request.body():
body = await request.json()
else:
body = None
with open(REQUEST_FILE, "a") as f:
f.write(f"{request.method} - FROM :: {request.client} TO :: {request.url}\n")
f.write(f"HEADERS :: \n{request.headers}\n")
f.write(f"BODY :: \n{body}\n")
f.write("\n\n")
f.write("=" * 15)
f.write("\n\n")
@app.get("/webhook")
async def get_webhook(request: Request):
check_file()
await write_request(request)
return {"status": "success"}
@app.post("/webhook")
async def post_webhook(request: Request):
check_file()
await write_request(request)
return {"status": "success"}
@app.get("/hello")
async def test_alive():
return "Hello from fast-http-server"