How to configure cors? #621
Replies: 3 comments 11 replies
-
hey @franciscohermida!
currently unsupported (going to sneak this in to 0.3.0 #622)
i haven't seem this before, but i changed how this works in the upcoming 0.3.0 which might fix it. can you drop a quick overview of your build system so i can try to reproduce? |
Beta Was this translation helpful? Give feedback.
-
I think the problem lies in this file: Don't know if this is related to Vite but the first import on line 6 works and code never reaches the catch block when in browser environment (or vite dev server at least). I changed the file to something like this and it seems to work: export async function importWebSocket(): Promise<typeof WebSocket> {
let _WebSocket: typeof WebSocket;
if (typeof WebSocket !== "undefined") {
// Browser environment
_WebSocket = WebSocket;
} else {
try {
// Node.js environment
const ws = await import("ws");
_WebSocket = ws.WebSocket as unknown as typeof WebSocket;
} catch {
// WS not available
_WebSocket = class MockWebSocket {
constructor() {
throw new Error(
'WebSocket support requires installing the "ws" package',
);
}
} as unknown as typeof WebSocket;
}
}
return _WebSocket;
} So basically first check if in browser environment and if so use native Websocket, if in node env then try to import ws. I'm using React Router 7 in framework mode (Vite). |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Trying to run the client in a vue vite app.
Also getting:
Uncaught (in promise) TypeError: WebSocket2 is not a constructor
Beta Was this translation helpful? Give feedback.
All reactions