support binary files

This commit is contained in:
Chris Wanstrath 2025-09-29 20:51:41 -07:00
parent ab47945222
commit 6480b94d78

View File

@ -16,6 +16,7 @@ type Response = {
status: number
headers: Record<string, string>,
body: string
isBinary?: boolean
}
type Success = {
@ -77,7 +78,7 @@ app.get("/tunnel", c => {
})
})
app.get("*", async c => {
app.all("*", async c => {
const url = new URL(c.req.url)
const localhost = url.hostname.endsWith("localhost")
const domains = url.hostname.split(".")
@ -107,6 +108,14 @@ app.get("*", async c => {
})
})
if (result.isBinary) {
const buffer = Buffer.from(result.body, 'base64')
return new Response(buffer, {
status: result.status,
headers: result.headers,
})
}
return new Response(result.body, {
status: result.status,
headers: result.headers,