This commit is contained in:
@ -1,5 +1,5 @@
|
||||
---
|
||||
import BoringLayout from '../components/BoringLayout.astro'
|
||||
import BoringLayout from '../layout/BoringLayout.astro'
|
||||
|
||||
const friends = [
|
||||
['https://omega98.top', '核子的博客'],
|
||||
|
||||
42
src/pages/api/legacy/[...path].ts
Normal file
42
src/pages/api/legacy/[...path].ts
Normal file
@ -0,0 +1,42 @@
|
||||
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 },
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,11 @@
|
||||
---
|
||||
import BoringLayout from '../components/BoringLayout.astro'
|
||||
import BoringLayout from '../layout/BoringLayout.astro'
|
||||
import MainpageButton from '../components/MainpageButton.svelte'
|
||||
---
|
||||
|
||||
<BoringLayout>
|
||||
<h1>博客系统翻新中...</h1>
|
||||
<p>点击 <a href="https://legacy.passthem.top">这里</a> 查看旧版博客</p>
|
||||
<p>或者了解更多 <a href="/about">关于这里</a></p>
|
||||
<p><MainpageButton client:only /></p>
|
||||
</BoringLayout>
|
||||
|
||||
Reference in New Issue
Block a user