How do I proxy a websocket request? #3588
Unanswered
unbiased-dev
asked this question in
Q&A
Replies: 2 comments
-
fetch does not support WebSocket. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I’m not sure if this approach is better, but http-proxy-middleware works fine. To use it with Hono, you need to bind HTTPBindings to Hono. Here’s an example of the setup: import { createProxyMiddleware } from "http-proxy-middleware";
import { type HttpBindings} from "@hono/node-server";
const proxy = createProxyMiddleware({
... your proxy setup
})
const app = new Hono<{ Bindings: HttpBindings }>();
app.use("*", (c, next) => {
return new Promise((resolve, reject) => {
proxy(c.env.incoming, c.env.outgoing, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
}); |
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
-
So I wrote a proxy to passthrough all my vite port requests to vite within my hono app.
This works fine however it throws when the websocket tries to connet for hot module reloading.
Here are the details of the requet
The response actually has a status of 200 but under the transferred column in the devtools instead of size it says
NS_ERROR_WEBSOCKET_CONNECTION_REFUSED
.Beta Was this translation helpful? Give feedback.
All reactions