forked from
quillmatiq.com/augment
Fork of Chiri for Astro for my blog
1export const prerender = false
2
3import type { APIContext } from 'astro'
4
5export async function GET(context: APIContext) {
6 const host = context.request.headers.get('host') || 'localhost:4321'
7 const url = new URL(context.request.url, `http://${host}`)
8 const target = url.searchParams.get('url')
9
10 if (!target) {
11 return new Response('Missing url param', { status: 400 })
12 }
13
14 try {
15 const res = await fetch(target, {
16 headers: {
17 'User-Agent': 'Mozilla/5.0'
18 }
19 })
20 const contentType = res.headers.get('content-type') || 'text/html'
21 const data = await res.text()
22 return new Response(data, {
23 status: 200,
24 headers: {
25 'Content-Type': contentType,
26 'Cache-Control': 'no-store',
27 'Access-Control-Allow-Origin': '*'
28 }
29 })
30 } catch {
31 return new Response('Proxy error', { status: 500 })
32 }
33}