diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0e5ac79 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.venv +__pycache__ \ No newline at end of file diff --git a/main.py b/main.py index cb7d2d2..89c9ced 100644 --- a/main.py +++ b/main.py @@ -1,14 +1,39 @@ from typing import Union from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware + +from pydantic import BaseModel app = FastAPI() +origins = [ + "http://localhost", + "http://localhost:8080", +] + +app.add_middleware( + CORSMiddleware, + allow_origins=origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) @app.get("/") -def root(): +def getroot(): return {"Hello": "World"} +class ApiBody(BaseModel): + username: str + password: str + +@app.post("/api") +def postapi(body: ApiBody): + print(body.username) + print(body.password) + return body + @app.get("/api") -def root(): +def getapi(): return {"Hello": "API!"} diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..539bcc2 --- /dev/null +++ b/run.sh @@ -0,0 +1 @@ +uvicorn main:app --reload