website icon indicating copy to clipboard operation
website copied to clipboard

WIP:Add reverse proxy example

Open iflamed opened this issue 4 months ago • 6 comments

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

iflamed avatar Oct 07 '24 15:10 iflamed