Skip to content

Commit d375ba2

Browse files
ADD, cors
1 parent 01704f6 commit d375ba2

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

core/config/config_all.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1-
import logging
1+
from fastapi.middleware.cors import CORSMiddleware
22

3-
# sem uso atualmente
4-
# Configurar o registro
5-
logging.basicConfig(level=logging.INFO,
6-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
7-
handlers=[logging.StreamHandler()])
3+
# caso precise de mais configuracao, documente e especifique porque
4+
def config_CORS(app):
5+
86

9-
logger = logging.getLogger(__name__)
7+
origins = [
8+
"http://localhost.tiangolo.com",
9+
"https://localhost.tiangolo.com",
10+
"http://localhost:5173/", # react
11+
"http://localhost:8080",
12+
]
13+
14+
app.add_middleware(
15+
CORSMiddleware,
16+
allow_origins=origins,
17+
allow_credentials=True,
18+
allow_methods=["GET", "POST", "PUT", "DELETE"],
19+
allow_headers=["Content-Type", "Authorization"],
20+
expose_headers=["X-Custom-Header"],
21+
max_age=3600,
22+
)

core/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from fastapi import FastAPI
22
from core.db.config import Base, engine
3+
from core.config.config_all import config_CORS
34

45
from core.api.routes import router
56
from core.api.all_routes import routes
@@ -11,6 +12,7 @@
1112
# Criando a aplicação FastAPI
1213
app = FastAPI()
1314

15+
config_CORS(app)
1416
routes(app)
1517

1618

core/test.db

28 KB
Binary file not shown.

0 commit comments

Comments
 (0)