-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
35 lines (28 loc) · 968 Bytes
/
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
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
from db import database, Familia, CestaBasica, Beneficiario, Coleta, Ong
from routers import Familias_router, Beneficiarios_router, Coletas_router, Cestas_router, Ongs_router
# Criar uma instância do aplicativo FastAPI
app = FastAPI(title= "API da ONG", version="1.0.0")
app.include_router(Familias_router)
app.include_router(Beneficiarios_router)
app.include_router(Coletas_router)
app.include_router(Cestas_router)
app.include_router(Ongs_router)
@app.on_event("startup")
async def startup():
await database.connect()
@app.on_event("shutdown")
async def shutdown():
await database.disconnect()
origins = ["*"]
app.add_middleware(
CORSMiddleware,
allow_methods=["*"],
allow_headers=["*"],
allow_credentials=True,
allow_origins=["*"]
)
if __name__ == "__main__":
uvicorn.run("main:app", host="localhost", port=7777, log_level="info")