Blorg-Backend/main.py

40 lines
667 B
Python

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 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 getapi():
return {"Hello": "API!"}