Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from pydantic import BaseModel, Field, HttpUrl
|
| 4 |
from typing import List
|
| 5 |
-
|
| 6 |
# -- 1. Define Pydantic Models for Data Validation --
|
| 7 |
|
| 8 |
# This model defines the structure of the incoming request JSON
|
|
@@ -35,6 +35,20 @@ app = FastAPI(
|
|
| 35 |
title="Backend Checker API",
|
| 36 |
description="A mock API to validate requests and send simulated responses."
|
| 37 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
# -- 3. Define the API Endpoint --
|
| 40 |
@app.post("/check", response_model=ResponsePacket)
|
|
|
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from pydantic import BaseModel, Field, HttpUrl
|
| 4 |
from typing import List
|
| 5 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
# -- 1. Define Pydantic Models for Data Validation --
|
| 7 |
|
| 8 |
# This model defines the structure of the incoming request JSON
|
|
|
|
| 35 |
title="Backend Checker API",
|
| 36 |
description="A mock API to validate requests and send simulated responses."
|
| 37 |
)
|
| 38 |
+
# ⬇️ ADD THIS MIDDLEWARE SECTION
|
| 39 |
+
# This tells the API to accept requests from your frontend
|
| 40 |
+
origins = [
|
| 41 |
+
"https://your-firebase-app-name.web.app", # Your production frontend URL
|
| 42 |
+
"http://localhost:3000", # Your local development URL
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
app.add_middleware(
|
| 46 |
+
CORSMiddleware,
|
| 47 |
+
allow_origins=origins,
|
| 48 |
+
allow_credentials=True,
|
| 49 |
+
allow_methods=["*"], # Allows all methods, including POST
|
| 50 |
+
allow_headers=["*"], # Allows all headers
|
| 51 |
+
)
|
| 52 |
|
| 53 |
# -- 3. Define the API Endpoint --
|
| 54 |
@app.post("/check", response_model=ResponsePacket)
|