add turborepo
This commit is contained in:
31
apps/id.saladeaula.digital/app/routes/upstream.ts
Normal file
31
apps/id.saladeaula.digital/app/routes/upstream.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { Route } from './+types'
|
||||
|
||||
export const loader = proxy
|
||||
export const action = proxy
|
||||
|
||||
async function proxy({
|
||||
request,
|
||||
context
|
||||
}: Route.ActionArgs): Promise<Response> {
|
||||
const pathname = new URL(request.url).pathname
|
||||
const url = new URL(pathname, context.cloudflare.env.ISSUER_URL)
|
||||
const headers = new Headers(request.headers)
|
||||
const response = await fetch(url.toString(), {
|
||||
method: request.method,
|
||||
headers,
|
||||
...(['GET', 'HEAD'].includes(request.method)
|
||||
? {}
|
||||
: { body: await request.text() })
|
||||
})
|
||||
|
||||
const contentType = response.headers.get('content-type') || ''
|
||||
const body =
|
||||
contentType.includes('application/json') || contentType.startsWith('text/')
|
||||
? await response.text()
|
||||
: await response.arrayBuffer()
|
||||
|
||||
return new Response(body, {
|
||||
status: response.status,
|
||||
headers: response.headers
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user