Jelajahi Sumber

Add CORS; revert back to previous index as it timed out deploying

Daoud Clarke 3 tahun lalu
induk
melakukan
a41088ca9a
2 mengubah file dengan 10 tambahan dan 2 penghapusan
  1. 2 2
      config/tinysearchengine.yaml
  2. 8 0
      mwmbl/tinysearchengine/create_app.py

+ 2 - 2
config/tinysearchengine.yaml

@@ -8,5 +8,5 @@ server_config:
 
 index_config:
   index_path: data/index.tinysearch
-  num_pages: 256000
-  page_size: 40960
+  num_pages: 25600
+  page_size: 4096

+ 8 - 0
mwmbl/tinysearchengine/create_app.py

@@ -5,6 +5,7 @@ from pathlib import Path
 from urllib.parse import urlparse
 
 from fastapi import FastAPI
+from starlette.middleware.cors import CORSMiddleware
 from starlette.responses import FileResponse
 from starlette.staticfiles import StaticFiles
 
@@ -20,6 +21,13 @@ SCORE_THRESHOLD = 0.25
 
 def create(tiny_index: TinyIndex):
     app = FastAPI()
+    
+    # Allow CORS requests from any site
+    app.add_middleware(
+        CORSMiddleware,
+        allow_origins=["*"],
+        allow_headers=["*"],
+    )
 
     @app.get("/search")
     def search(s: str):