From d30bc3a4662a7f93565f8b4917c627ab8959f79c Mon Sep 17 00:00:00 2001 From: Travis Rivers <trivers@contractor.usgs.gov> Date: Tue, 1 Sep 2020 11:04:37 -0600 Subject: [PATCH] add middleware to both apps --- geomagio/api/secure/app.py | 8 ++++++++ geomagio/api/ws/CORSMiddleware.py | 0 geomagio/api/ws/app.py | 5 +++-- 3 files changed, 11 insertions(+), 2 deletions(-) delete mode 100644 geomagio/api/ws/CORSMiddleware.py diff --git a/geomagio/api/secure/app.py b/geomagio/api/secure/app.py index 753b9e3bc..81aaacb1f 100644 --- a/geomagio/api/secure/app.py +++ b/geomagio/api/secure/app.py @@ -33,6 +33,14 @@ app.include_router(login_router) app.include_router(metadata_router) +@app.middleware("http") +async def add_headers(request: Request, call_next): + response = await call_next(request) + response.headers["Access-Control-Allow-Origin"] = "*" + response.headers["Cache-Control"] = "no-cache" + return response + + @app.get("/") async def index(request: Request, user: User = Depends(current_user)): """Route to demo user login.""" diff --git a/geomagio/api/ws/CORSMiddleware.py b/geomagio/api/ws/CORSMiddleware.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/geomagio/api/ws/app.py b/geomagio/api/ws/app.py index 9038d972d..56c4b8aaf 100644 --- a/geomagio/api/ws/app.py +++ b/geomagio/api/ws/app.py @@ -32,9 +32,10 @@ app.include_router(observatories.router) @app.middleware("http") -async def add_process_time_header(request: Request, call_next): +async def add_headers(request: Request, call_next): response = await call_next(request) - response.headers["X-Process-Time"] = "45" + response.headers["Access-Control-Allow-Origin"] = "*" + response.headers["Cache-Control"] = "864000" return response -- GitLab