Spaces:
Running
Running
Cors Policy
Browse files
app.py
CHANGED
|
@@ -2,10 +2,28 @@ import funciones
|
|
| 2 |
from fastapi import FastAPI, Form, HTTPException
|
| 3 |
from fastapi.responses import JSONResponse
|
| 4 |
from typing import Optional
|
| 5 |
-
import
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
# Nuevo endpoint para Health Check
|
| 10 |
@app.get("/health",
|
| 11 |
tags=["Health Check"],
|
|
|
|
| 2 |
from fastapi import FastAPI, Form, HTTPException
|
| 3 |
from fastapi.responses import JSONResponse
|
| 4 |
from typing import Optional
|
| 5 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
| 9 |
+
# Configuración de CORS
|
| 10 |
+
origins = [
|
| 11 |
+
"http://localhost",
|
| 12 |
+
"http://localhost:8000", # Si usas algún puerto específico para tu frontend
|
| 13 |
+
"http://127.0.0.1:5500", # Puerto común de Live Server
|
| 14 |
+
"https://buy.splashmix.com", # Si despliegas tu frontend, añade su dominio aquí
|
| 15 |
+
#"*" # ¡CUIDADO! '*' permite CUALQUIER origen. Úsalo solo para desarrollo o si sabes lo que haces.
|
| 16 |
+
# Es más seguro especificar orígenes concretos en producción.
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
app.add_middleware(
|
| 20 |
+
CORSMiddleware,
|
| 21 |
+
allow_origins=origins,
|
| 22 |
+
allow_credentials=True, # Permite cookies, cabeceras de autorización, etc.
|
| 23 |
+
allow_methods=["*"], # Permite todos los métodos (GET, POST, PUT, DELETE, etc.)
|
| 24 |
+
allow_headers=["*"], # Permite todas las cabeceras
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
# Nuevo endpoint para Health Check
|
| 28 |
@app.get("/health",
|
| 29 |
tags=["Health Check"],
|