Fork of Chiri for Astro for my blog
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at bcd31bfa38a6de9fbb609d7d564d453959a9a365 33 lines 877 B view raw
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}