02 · Applications
Reverse proxy to an upstream service
Forward every request under /api/* to another origin, preserving method, headers, query string and body. Streams back the upstream Response directly.
Code
proxy.js
const { WebApp } = require(class="tk-str">39;@hyperbridge/forge/server39;); const app = new WebApp(); app.all(class="tk-str">39;/api/*39;, async (c) => { const url = new URL(c.req.url); const upstream = class="tk-str">39;https:class="tk-cm">//api.example.com39; + url.pathname.replace(class="tk-str">39;/api39;, class="tk-str">39;39;) + url.search; return fetch(upstream, { method: c.req.method, headers: c.req.header(), body: [class="tk-str">39;GET39;,class="tk-str">39;HEAD39;].includes(c.req.method) ? undefined : await c.req.arrayBuffer(), }); }); app.listen(3000);
How it works
Returning the upstream Response directly is zero-copy — the body never buffers in your process. WebApp's runtime passes the body stream straight to the client.
c.req.header() returns a plain object of every header, which fetch() accepts as its headers option. c.req.arrayBuffer() is cached, so calling other body methods later won't throw.
On Cloudflare Workers, this becomes a true edge proxy: requests hop into your Worker, are forwarded, and stream back without crossing your origin again.
Try it
Quickstart
curl http://localhost:3000/api/users → forwarded to api.example.com/users
Related modules
This is HBForge's port of Hono's example. Read the original at hono.dev/examples/proxy.