apteryxxyz / next-ws

Add support for WebSockets in Next.js app directory.
https://npmjs.com/next-ws
171 stars 12 forks source link

How to access to params using dynamic route #30

Closed AugustinMauroy closed 2 months ago

AugustinMauroy commented 6 months ago

I thinks everytings is on title

apteryxxyz commented 6 months ago

The second parameter passed to the SOCKET function is an IncomingMessage object from the Node.js http module. You can use that to get everything related to the request including the URL.

AugustinMauroy commented 6 months ago

Ok ! Thanks but why do you think about having something like that:

export function SOCKET({
  client: import('ws').WebSocket,
  request: import('http').IncomingMessage,
  server: import('ws').WebSocketServer,
  params: YourParamsType
}) {
  // ...
}

So parameter of function is one object. Like Get methods of next

chinna2580 commented 2 months ago

@apteryxxyz dyamic path routes are not working using next-ws, it throws 'could not find module for page /api/socket/history' this is in path /api/socket/[api_type]/route.ts file, it doesnt read this path

apteryxxyz commented 2 months ago

@apteryxxyz dyamic path routes are not working using next-ws, it throws 'could not find module for page /api/socket/history' this is in path /api/socket/[api_type]/route.ts file, it doesnt read this path

Fixed in next-ws@1.1.1.

apteryxxyz commented 2 months ago

Speaking of this issue, I'm gonna go ahead and close it, you can get the params from the request parameter. I want to avoid adding more parameters to the SOCKET function, and I'm not even sure if next-ws can access the names of dynamic segments.