-
-
Notifications
You must be signed in to change notification settings - Fork 610
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
Add support for reverse proxy #1491
Comments
Hi @allmors I think it is not needed. We can write a reverse proxy with this code: import { Hono } from 'hono'
const app = new Hono()
app.all('*', async (c) => {
const res = await fetch(c.req.raw)
// ...
const newResponse = new Response(res.body, res)
// ...
return newResponse
})
export default app Related: #1414 |
Thank you @yusukebe but I tested it and it caused 404 on some websites. |
Which platform do you run it on? Perhaps, you don't set up an "origin". If you don't have it, you can specify a url: app.all('*', async (c) => {
const res = await fetch('http://example.com') // <==
console.log(res.status)
// ...
const newResponse = new Response(res.body, res)
// ...
return newResponse
}) |
I'm using hono in cloudflare workers, the following is my test code
|
For Cloudflare Workers, the following will not work without an origin. const res = await fetch(c.req.raw) However, if you just want to proxy, the following may be sufficient, what do you think? const res = await fetch('https://fabfilters.online/', c.req.raw) |
thanks @yusukebe |
Hi, I have tried the above code on Nodejs but it not proxy to example.com URL. Is it only work in Cloudfare ?? |
Hi @kongminh113 ! Thanks! It seems to be a bug! I've created the issue: honojs/node-server#121 |
What is the feature you are proposing?
I hope to add support for reverse proxy. It supports functions similar to http-proxy-middilware in hono app.use. If someone can tell me how hono implements the reverse proxy function of cfworkers, it would also be great.
The text was updated successfully, but these errors were encountered: