Websocket Support
qodzero opened this issue · 3 comments
Hi, Im using this template for my project but I can't get websockets to work at all.
I simply added a quick websocket test to backend/app/main.py:
@app.websocket("/ws/{some_id}")
async def ws_test(websocket: WebSocket):
await websocket.accept()
print("Accepted")When I visit http://localhost, I can see the default blog as expected, however when I connect to ws://localhost/ws/some-id using a websocket client, nothing happens, nothing printed on the server console either. The server just spits out:
"GET /ws/some-id HTTP/1.1" 200 14635 "-" "-" 171 "myapp-com-frontend-http@docker"
Could you help me on how to add websocket support here?
Hi @qodzero ... the base generator doesn't have websockets built in, although I have used them in projects. You need both a FastAPI endpoint, as well as the Nuxt3 integrations. The backend basically acts as a listener in a perpetual while do loop for as long as the socket is open. But that's all controlled from the frontend.
I'll try and put a help guide together, but that might not be immediate if you're on a deadline?
I'm not in much of a deadline, it's a personal project and I've managed to come up with a fix for the websocket integration. This can be closed now
Hey @qodzero ... got your Websockets guide. Relatively simplified, but shows you how I run websockets with FastAPI and Nuxt.