Fix cors origin (#525)
This commit is contained in:
parent
fb9b8a8c83
commit
f37540286c
@ -75,7 +75,7 @@ class App(Base):
|
|||||||
|
|
||||||
# Set up the API.
|
# Set up the API.
|
||||||
self.api = FastAPI()
|
self.api = FastAPI()
|
||||||
self.add_cors(config.cors_allowed_origins)
|
self.add_cors()
|
||||||
self.add_default_endpoints()
|
self.add_default_endpoints()
|
||||||
|
|
||||||
# Set up CORS options.
|
# Set up CORS options.
|
||||||
@ -124,16 +124,10 @@ class App(Base):
|
|||||||
# To test the server.
|
# To test the server.
|
||||||
self.api.get(str(constants.Endpoint.PING))(ping)
|
self.api.get(str(constants.Endpoint.PING))(ping)
|
||||||
|
|
||||||
def add_cors(self, allowed_origins: Optional[List[str]] = None):
|
def add_cors(self):
|
||||||
"""Add CORS middleware to the app.
|
"""Add CORS middleware to the app."""
|
||||||
|
|
||||||
Args:
|
|
||||||
allowed_origins: A list of allowed origins.
|
|
||||||
"""
|
|
||||||
allowed_origins = allowed_origins or ["*"]
|
|
||||||
self.api.add_middleware(
|
self.api.add_middleware(
|
||||||
cors.CORSMiddleware,
|
cors.CORSMiddleware,
|
||||||
allow_origins=allowed_origins,
|
|
||||||
allow_credentials=True,
|
allow_credentials=True,
|
||||||
allow_methods=["*"],
|
allow_methods=["*"],
|
||||||
allow_headers=["*"],
|
allow_headers=["*"],
|
||||||
|
Loading…
Reference in New Issue
Block a user