Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: websocket route path not inherited prefix value #3280

Closed
wants to merge 1 commit into from
Closed

Fix: websocket route path not inherited prefix value #3280

wants to merge 1 commit into from

Conversation

AngusWG
Copy link

@AngusWG AngusWG commented May 24, 2021

websocket route path not inherited prefix value

In my case:

router = APIRouter(prefix = '/asset')
@router.websocket_route("/ws")
async def ws_func(ws: WebSocket):
    ....
app.include_router(router)

ws_func path should be /asset/ws .
but ws_func path is /ws .
I found starlette WebSocketRoute not have prefix attribute.

we need override add_websocket_route method for add router prefix .

@Kludex
Copy link
Sponsor Collaborator

Kludex commented May 24, 2021

I guess that issue should also be solved by #2640

@AngusWG AngusWG closed this May 24, 2021
@AngusWG
Copy link
Author

AngusWG commented May 24, 2021

I guess that issue should also be solved by #2640

Thank you for answer.

@AngusWG
Copy link
Author

AngusWG commented May 24, 2021

https://github.com/tiangolo/fastapi/blob/0.65.1/fastapi/routing.py#L583

@Kludex

It seems that the latest version does not have 8843fe8 code

@AngusWG AngusWG reopened this May 24, 2021
@AngusWG AngusWG closed this May 24, 2021
@Kludex
Copy link
Sponsor Collaborator

Kludex commented May 24, 2021

I mean, it was not merged, but it solves the issue 😅

@tiangolo needs to review it 😗

@AngusWG
Copy link
Author

AngusWG commented May 24, 2021

Hope to be release soon. 😂

@genagurbanguliyev
Copy link

genagurbanguliyev commented Feb 15, 2024

use websocket not websocket_route
try this:

router = APIRouter(prefix = '/asset')
@router.websocket("/ws")
async def ws_func(ws: WebSocket):
    ....
app.include_router(router)

This works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants