website
website copied to clipboard
WIP:Add reverse proxy example
Simple to use!
import { Hono } from 'hono'
const app = new Hono()
app.all('*', async (c) => {
const api = new URL('https://www.example.com')
const url = new URL(c.req.url)
url.protocol = api.protocol
url.host = api.host
url.port = api.port
const upstream = url.toString()
return await fetch(upstream, {
method: c.req.raw.method,
body: c.req.raw.body,
credentials: c.req.raw.credentials,
cache: c.req.raw.cache,
headers: c.req.raw.headers,
referrer: c.req.raw.referrer,
referrerPolicy: c.req.raw.referrerPolicy,
integrity: c.req.raw.integrity,
keepalive: false,
mode: c.req.raw.mode,
redirect: 'manual'
})
})
export default app