Spaces:
Running
Running
added cors
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from preditormodels import PhishingPredictor
|
| 2 |
import re
|
| 3 |
from fastapi import FastAPI, HTTPException
|
|
|
|
| 4 |
from pydantic import BaseModel, field_validator
|
| 5 |
from config import XGB_MODEL_PATH, BERT_MODEL_PATH
|
| 6 |
class EmailRequest(BaseModel):
|
|
@@ -21,6 +22,22 @@ class EmailRequest(BaseModel):
|
|
| 21 |
|
| 22 |
app = FastAPI(title="Phishing Detection API")
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
# Load models once
|
| 26 |
predictor = PhishingPredictor(BERT_MODEL_PATH, XGB_MODEL_PATH)
|
|
|
|
| 1 |
from preditormodels import PhishingPredictor
|
| 2 |
import re
|
| 3 |
from fastapi import FastAPI, HTTPException
|
| 4 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 5 |
from pydantic import BaseModel, field_validator
|
| 6 |
from config import XGB_MODEL_PATH, BERT_MODEL_PATH
|
| 7 |
class EmailRequest(BaseModel):
|
|
|
|
| 22 |
|
| 23 |
app = FastAPI(title="Phishing Detection API")
|
| 24 |
|
| 25 |
+
# Define the specific origins that are allowed to call this API
|
| 26 |
+
origins = [
|
| 27 |
+
"http://localhost:3000", # React/Frontend local development
|
| 28 |
+
"http://127.0.0.1:5500", # VS Code Live Server default
|
| 29 |
+
"http://127.0.0.1:8500", # Your FastAPI local address
|
| 30 |
+
"http://localhost:5500", # Alternative Live Server address
|
| 31 |
+
]
|
| 32 |
+
|
| 33 |
+
app.add_middleware(
|
| 34 |
+
CORSMiddleware,
|
| 35 |
+
allow_origins=origins, # Only allow the domains in the list above
|
| 36 |
+
allow_credentials=True,
|
| 37 |
+
allow_methods=["*"], # Allows all HTTP methods (POST, GET, etc.)
|
| 38 |
+
allow_headers=["*"], # Allows all headers (Content-Type, etc.)
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
|
| 42 |
# Load models once
|
| 43 |
predictor = PhishingPredictor(BERT_MODEL_PATH, XGB_MODEL_PATH)
|