-
Notifications
You must be signed in to change notification settings - Fork 48
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
Proxy is not working #121
Comments
Although On my environment, the following code returned the correct content. I have not yet figured out whether this process should be done by each app or by the node-server. app.get('/proxy', async (c) => {
const res = await fetch('https://example.com/')
const headers = { ...res.headers }
delete headers['content-encoding']
delete headers['content-length']
const newResponse = new Response(res.body, { headers })
return newResponse
}) |
this works well, modified from https://github.com/linnil1/hono-cf-proxy/blob/main/src/utils_basic.ts function basicProxy(proxy_url = ""): Handler {
return async (c) => {
// remove prefix
// prefix = /app1/*, path = /app1/a/b
// => suffix_path = /a/b
// let path = new URL(c.req.raw.url).pathname
let path = c.req.path;
path = path.replace(new RegExp(`^${c.req.routePath.replace("*", "")}`), "/");
let url = proxy_url ? proxy_url + path : c.req.url;
// add params to URL
if (c.req.query()) url = url + "?" + new URLSearchParams(c.req.query());
// request
const rep = await fetch(url, {
method: c.req.method,
headers: c.req.raw.headers,
body: c.req.raw.body,
duplex: "half",
});
if (rep.status === 101) return rep;
return new Response(rep.body, rep);
};
} |
The following a "proxy pattern" is not working:
Commented honojs/hono#1491 (comment)
The text was updated successfully, but these errors were encountered: