Docker Space POST endpoint 404/HTML error — routing never reaches FastAPI container

Try this fix, hope so it will solve it

The most likely problem is in your Dockerfile command. Try changing this line:

Current:CMD ["uvicorn", "app:app", "–host", "0.0.0.0", "–port", "7860"]

Fix: CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]

(Notice the double dashes -- instead of single dashes)

If That Doesn’t Work

Add this to your app.py to help with routing:

from fastapi.middleware.cors import CORSMiddleware

app.add_middleware(
CORSMiddleware,
allow_origins=[““],
allow_methods=[”
”],
allow_headers=[“*”],
)

The do a quick test.

Add a simple POST route to test:

@app.post(“/test”)
async def test_post():
return {“message”: “POST works!”}

That’s it! The issue is with how Hugging Face routes requests to your container, not your code. These small changes should fix it. Good luck!

2 Likes