不再转发 API
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-03-31 23:20:54 +08:00
parent e79d768a6d
commit 17a6506bd6

View File

@ -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 },
)
}
}