feat(api): add CORSMiddleware to api routing
This commit is contained in:
@@ -16,6 +16,7 @@ def build_app(api_bundle: ApiBundle) -> FastAPI:
|
|||||||
app.state.api = api_bundle
|
app.state.api = api_bundle
|
||||||
app.mount("/static", StaticFiles(directory=root_path / "static/dist"))
|
app.mount("/static", StaticFiles(directory=root_path / "static/dist"))
|
||||||
doc.mount(app)
|
doc.mount(app)
|
||||||
app.include_router(api.router)
|
api.app.state.api = api_bundle
|
||||||
|
app.mount("/api", api.app)
|
||||||
app.include_router(view.router)
|
app.include_router(view.router)
|
||||||
return app
|
return app
|
||||||
|
|||||||
@@ -1,7 +1,15 @@
|
|||||||
from fastapi import APIRouter
|
from fastapi import FastAPI
|
||||||
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
from . import schedule, weather
|
from . import schedule, weather
|
||||||
|
|
||||||
router = APIRouter(prefix="/api")
|
app = FastAPI(openapi_prefix="/api")
|
||||||
router.include_router(weather.router)
|
app.add_middleware(
|
||||||
router.include_router(schedule.router)
|
CORSMiddleware,
|
||||||
|
allow_origins=["*"],
|
||||||
|
allow_credentials=True,
|
||||||
|
allow_methods=["*"],
|
||||||
|
allow_headers=["*"],
|
||||||
|
)
|
||||||
|
app.include_router(weather.router)
|
||||||
|
app.include_router(schedule.router)
|
||||||
|
|||||||
Reference in New Issue
Block a user