Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from pathlib import Path

from fastapi import FastAPI, HTTPException, Response
import requests

from fastapi import FastAPI, HTTPException, Response, Request
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles

Expand Down Expand Up @@ -34,7 +36,7 @@

app = FastAPI(title="NASA Sky Explorer Prototype")
app.mount("/assets", StaticFiles(directory=ASSETS_DIR), name="frontend-assets")
app.mount("/static", StaticFiles(directory=WEB_DIR), name="legacy-static")
app.mount("/static", StaticFiles(directory=BASE_DIR / "static"), name="legacy-static")


def _read_html(path: Path) -> str:
Expand Down Expand Up @@ -65,6 +67,18 @@ def favicon() -> Response:
return Response(content=FAVICON_SVG, media_type="image/svg+xml")


@app.get("/proxy/", include_in_schema=False)
def proxy(request: Request) -> Response:
"""Proxy requests to avoid CORS"""
try:
request = requests.get(request.query_params["q"])
request.raise_for_status()
except Exception:
raise HTTPException(status_code=404, detail="Can't request url.")
else:
return Response(content=request.content, media_type="text/html")


if __name__ == "__main__":
import uvicorn

Expand Down
Loading