Serve frontends via FastAPI static files to fix Brave browser file access block
Each backend now mounts its frontend directory at /ui/ so the UIs are accessible via http://localhost:800x/ui/ instead of file:// URLs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@ import array
|
|||||||
from fastapi import FastAPI, Query
|
from fastapi import FastAPI, Query
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
|
from fastapi.staticfiles import StaticFiles
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from db_oracle import get_connection
|
from db_oracle import get_connection
|
||||||
from embedder import embed_text
|
from embedder import embed_text
|
||||||
@@ -11,8 +12,11 @@ load_dotenv()
|
|||||||
|
|
||||||
PHOTOS_DIR = os.getenv("PHOTOS_DIR")
|
PHOTOS_DIR = os.getenv("PHOTOS_DIR")
|
||||||
|
|
||||||
|
FRONTEND_DIR = os.path.join(os.path.dirname(__file__), "../../oravector-demo/frontend")
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"])
|
app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"])
|
||||||
|
app.mount("/ui", StaticFiles(directory=os.path.abspath(FRONTEND_DIR), html=True), name="ui")
|
||||||
|
|
||||||
@app.get("/search")
|
@app.get("/search")
|
||||||
def search(q: str = Query(...), limit: int = Query(12)):
|
def search(q: str = Query(...), limit: int = Query(12)):
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import os
|
|||||||
from fastapi import FastAPI, Query
|
from fastapi import FastAPI, Query
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
|
from fastapi.staticfiles import StaticFiles
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from db_oracle import get_connection_indb
|
from db_oracle import get_connection_indb
|
||||||
|
|
||||||
@@ -9,8 +10,11 @@ load_dotenv()
|
|||||||
|
|
||||||
PHOTOS_DIR = os.getenv("PHOTOS_DIR")
|
PHOTOS_DIR = os.getenv("PHOTOS_DIR")
|
||||||
|
|
||||||
|
FRONTEND_DIR = os.path.join(os.path.dirname(__file__), "../../oravector-demo/frontend")
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"])
|
app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"])
|
||||||
|
app.mount("/ui", StaticFiles(directory=os.path.abspath(FRONTEND_DIR), html=True), name="ui")
|
||||||
|
|
||||||
@app.get("/search")
|
@app.get("/search")
|
||||||
def search(q: str = Query(...), limit: int = Query(12)):
|
def search(q: str = Query(...), limit: int = Query(12)):
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import os
|
|||||||
from fastapi import FastAPI, Query
|
from fastapi import FastAPI, Query
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
|
from fastapi.staticfiles import StaticFiles
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from db import get_connection
|
from db import get_connection
|
||||||
from embedder import embed_text
|
from embedder import embed_text
|
||||||
@@ -10,8 +11,11 @@ load_dotenv()
|
|||||||
|
|
||||||
PHOTOS_DIR = os.getenv("PHOTOS_DIR")
|
PHOTOS_DIR = os.getenv("PHOTOS_DIR")
|
||||||
|
|
||||||
|
FRONTEND_DIR = os.path.join(os.path.dirname(__file__), "../../pgvector-demo/frontend")
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"])
|
app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=["*"], allow_headers=["*"])
|
||||||
|
app.mount("/ui", StaticFiles(directory=os.path.abspath(FRONTEND_DIR), html=True), name="ui")
|
||||||
|
|
||||||
@app.get("/search")
|
@app.get("/search")
|
||||||
def search(q: str = Query(...), limit: int = Query(12)):
|
def search(q: str = Query(...), limit: int = Query(12)):
|
||||||
|
|||||||
Reference in New Issue
Block a user