Dev local #2
2 changed files with 4 additions and 25 deletions
22
main.py
22
main.py
|
|
@ -11,46 +11,28 @@ app = FastAPI(
|
||||||
)
|
)
|
||||||
|
|
||||||
# CORS configuration
|
# CORS configuration
|
||||||
origins = [
|
|
||||||
FRONTEND_URL,
|
|
||||||
"http://localhost",
|
|
||||||
"http://localhost:5173",
|
|
||||||
"http://0.0.0.0",
|
|
||||||
"http://0.0.0.0:5173",
|
|
||||||
"*"
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=origins,
|
allow_origins=["*"], # Only wildcard
|
||||||
allow_credentials=True,
|
allow_credentials=False, # Changed to False to work with wildcard
|
||||||
allow_methods=["*"],
|
allow_methods=["*"],
|
||||||
allow_headers=["*"],
|
allow_headers=["*"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Basic root endpoint
|
# Basic root endpoint
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
async def root():
|
async def root():
|
||||||
return {"message": "Welcome to your FastAPI application"}
|
return {"message": "Welcome to your FastAPI application"}
|
||||||
|
|
||||||
|
|
||||||
# Health check endpoint
|
# Health check endpoint
|
||||||
@app.get("/health")
|
@app.get("/health")
|
||||||
async def health_check():
|
async def health_check():
|
||||||
return {"status": "healthy"}
|
return {"status": "healthy"}
|
||||||
|
|
||||||
|
|
||||||
app.include_router(fact_check_router, prefix="")
|
app.include_router(fact_check_router, prefix="")
|
||||||
app.include_router(aifact_check_router, prefix="")
|
app.include_router(aifact_check_router, prefix="")
|
||||||
app.include_router(scrap_websites_router, prefix="")
|
app.include_router(scrap_websites_router, prefix="")
|
||||||
|
|
||||||
# Include routers (uncomment and modify as needed)
|
|
||||||
# from routes import some_router
|
|
||||||
# app.include_router(some_router, prefix="/your-prefix", tags=["your-tag"])
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|
||||||
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
|
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
|
||||||
|
|
@ -3,19 +3,16 @@ from main import app
|
||||||
|
|
||||||
client = TestClient(app)
|
client = TestClient(app)
|
||||||
|
|
||||||
|
|
||||||
def test_root_endpoint():
|
def test_root_endpoint():
|
||||||
response = client.get("/")
|
response = client.get("/")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"message": "Welcome to your FastAPI application"}
|
assert response.json() == {"message": "Welcome to your FastAPI application"}
|
||||||
|
|
||||||
|
|
||||||
def test_health_endpoint():
|
def test_health_endpoint():
|
||||||
response = client.get("/health")
|
response = client.get("/health")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"status": "healthy"}
|
assert response.json() == {"status": "healthy"}
|
||||||
|
|
||||||
|
|
||||||
def test_cors_headers():
|
def test_cors_headers():
|
||||||
response = client.get("/", headers={"Origin": "http://localhost:5173"})
|
response = client.get("/", headers={"Origin": "http://localhost:5173"})
|
||||||
assert response.headers["access-control-allow-origin"] == "http://localhost:5173"
|
assert response.headers["access-control-allow-origin"] == "*"
|
||||||
Loading…
Add table
Reference in a new issue