Switch to fastapi

This commit is contained in:
Jimmy 2021-07-26 21:02:22 +12:00
parent 19c8b98924
commit 1ddd966b38
1 changed files with 22 additions and 11 deletions

View File

@ -1,14 +1,25 @@
from aiohttp import web from os import environ
import os
from fastapi import FastAPI, Body, Request, Depends
import json
from fastapi.exceptions import HTTPException
async def handle(request): from fastapi.param_functions import Header
name = request.match_info.get('name', "Anonymous") from fastapi_responses import custom_openapi
text = "Hello, " + name from auth import auth_hook, auth_web, check_ref
return web.Response(text=text)
if not os.environ.get("DOCKER"):
from dotenv import load_dotenv
load_dotenv
app = FastAPI()
app.openapi = custom_openapi(app)
@app.get("/", dependencies=[Depends(auth_web)])
@app.post("/", dependencies=[Depends(auth_hook), Depends(check_ref)])
async def hook(req: Request):
return "Update"
app = web.Application()
app.add_routes([web.get('/', handle),
web.get('/{name}', handle)])
if __name__ == '__main__':
print("Starting")
web.run_app(app)