Files
Starlight_Lancher_animation_up/netlify/functions/releases-latest.mjs

28 lines
1.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Netlify Function转发最新版本元数据。
// 客户端直连 CNB 会被 CORS 拦截CNB 只放行 docs.cnb.cool
// 由本站服务器代为拉取(服务器无 CORS 限制),每次请求实时转发。
const CNB_URL =
'https://cnb.cool/axlmc/Axolotl/-/git/raw/main/apps/website/releases/latest.json'
export default async () => {
try {
const response = await fetch(CNB_URL, {
headers: { 'User-Agent': 'Axolotl-Website' },
signal: AbortSignal.timeout(8000),
})
if (!response.ok) {
return new Response(`CNB source returned ${response.status}`, { status: 502 })
}
return new Response(await response.text(), {
headers: {
'Content-Type': 'application/json',
// 浏览器不缓存每次访问实时请求Netlify CDN 边缘缓存 5 分钟
// 以节省 Function 调用额度;错误响应不缓存。
'Cache-Control': 'public, max-age=0, s-maxage=300',
},
})
} catch (error) {
return new Response(`Failed to fetch release metadata: ${error.message}`, { status: 502 })
}
}