This commit is contained in:
@ -1,42 +0,0 @@
|
||||
import type { APIRoute } from 'astro'
|
||||
import axios from 'axios'
|
||||
|
||||
export const prerender = false
|
||||
export const ALL: APIRoute = async ({ params, request }) => {
|
||||
const { path } = params
|
||||
const legacyBaseUrl =
|
||||
import.meta.env.LEGACY_SERVER_URL || 'https://legacy.passthem.top/api'
|
||||
|
||||
const targetUrl = `${legacyBaseUrl}/${path}`
|
||||
const headers = Object.fromEntries(request.headers.entries())
|
||||
|
||||
delete headers['host']
|
||||
delete headers['connection']
|
||||
|
||||
try {
|
||||
const response = await axios({
|
||||
method: request.method,
|
||||
url: targetUrl,
|
||||
data:
|
||||
request.method !== 'GET'
|
||||
? await request.json().catch(() => null)
|
||||
: undefined,
|
||||
headers,
|
||||
params: Object.fromEntries(new URL(request.url).searchParams),
|
||||
validateStatus: () => true,
|
||||
responseType: 'arraybuffer',
|
||||
})
|
||||
|
||||
return new Response(response.data, {
|
||||
status: response.status,
|
||||
headers: {
|
||||
'Content-Type': response.headers['content-type'] || 'application/json',
|
||||
},
|
||||
})
|
||||
} catch (error: any) {
|
||||
return new Response(
|
||||
JSON.stringify({ error: 'Gateway Error', message: error.message }),
|
||||
{ status: 502 },
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user