Skip to content

Commit 4babd7a

Browse files
committed
cors added.
1 parent 3993589 commit 4babd7a

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

main.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
1-
from typing import Union
2-
31
from fastapi import FastAPI
2+
from fastapi.middleware.cors import CORSMiddleware
3+
import logging
4+
5+
app = FastAPI(title="api")
6+
7+
logging.basicConfig(
8+
level=logging.INFO,
9+
format="%(asctime)s [%(name)s] %(levelname)s: %(message)s",
10+
)
11+
logger = logging.getLogger(__name__)
12+
13+
origins = [
14+
"http://localhost/ping",
15+
"http://localhost",
16+
"http://localhost:8080",
17+
]
418

5-
app = FastAPI()
19+
app.add_middleware(
20+
CORSMiddleware,
21+
allow_origins=origins,
22+
allow_credentials=True,
23+
allow_methods=["*"],
24+
allow_headers=["*"],
25+
)
626

727

828
@app.get("/ping")
929
def read_root():
30+
logging.info("GET '/ping'")
1031
return "pong"

0 commit comments

Comments
 (0)