Replies: 1 comment
-
You can achieve this using the URL API: function webSocketURL(url) {
const absolute = new URL(url, window.location.href);
absolute.protocol = absolute.protocol.replace("http", "ws");
return absolute.toString();
}
// ...
const { data, error } = useSWRSubscription("/path/to/socket", (key, { next }) => {
const socket = new WebSocket(webSocketURL(key))
// ...
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
When I'm using normal SWR, I can put in relative URLs because of the proxy I have setup in my NextJS project.
In another part of my project, I have a websocket that I would like to use the
useSWRSubscription
hook with. In the docs though, it show this as an example.Since there is a
ws://
there instead ofhttps://
, can I still put relative URLs such as/api/relative/route
and just have it use the proxy?Beta Was this translation helpful? Give feedback.
All reactions