forked from VinokurovVE/tests
first init
This commit is contained in:
31
main.py
Normal file
31
main.py
Normal file
@ -0,0 +1,31 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import HTMLResponse
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
app = FastAPI()
|
||||
origins = [
|
||||
"http://localhost",
|
||||
"http://localhost:8000",
|
||||
"http://localhost:3000",
|
||||
]
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=origins,
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
@app.get("/")
|
||||
def index():
|
||||
html_content = "<h2>Hello METANIT.COM!</h2>"
|
||||
return HTMLResponse(content=html_content)
|
||||
|
||||
@app.get("/cat")
|
||||
async def get_data():
|
||||
return {"firstname": "Котофей","lastname":"Барсикофф","age":"10"}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
uvicorn.run(app, host="0.0.0.0", port=8000, reload=True)
|
Reference in New Issue
Block a user