mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-25 17:14:57 +02:00
Reduce Vercel execution costs and Upstash Redis read counts by letting the CDN absorb more traffic. Addresses the "double dip" where bootstrap.js hit Redis for 15 keys on every 60s cache miss, and telegram-feed/geo had no s-maxage at all (every request hit Vercel). - bootstrap: s-maxage 60→600, add stale-if-error=900 - ais-snapshot: s-maxage 180→300, stale-while-revalidate 300→600 - oref-alerts: s-maxage 5→180, add stale-if-error=600 - telegram-feed: add s-maxage=600, stale-if-error=900 (had none) - geo: add s-maxage=3600, stale-if-error=3600 (had none) - gpsjam: add stale-if-error=3600 - opensky: add stale-if-error=300 - version: add stale-if-error=3600 - download: add stale-if-error=600
46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
// Non-sebuf: returns XML/HTML, stays as standalone Vercel function
|
|
export const config = { runtime: 'edge' };
|
|
|
|
const RELEASES_URL = 'https://api.github.com/repos/koala73/worldmonitor/releases/latest';
|
|
|
|
export default async function handler() {
|
|
try {
|
|
const res = await fetch(RELEASES_URL, {
|
|
headers: {
|
|
'Accept': 'application/vnd.github+json',
|
|
'User-Agent': 'WorldMonitor-Version-Check',
|
|
},
|
|
});
|
|
|
|
if (!res.ok) {
|
|
return new Response(JSON.stringify({ error: 'upstream' }), {
|
|
status: 502,
|
|
headers: { 'Content-Type': 'application/json' },
|
|
});
|
|
}
|
|
|
|
const release = await res.json();
|
|
const tag = release.tag_name ?? '';
|
|
const version = tag.replace(/^v/, '');
|
|
|
|
return new Response(JSON.stringify({
|
|
version,
|
|
tag,
|
|
url: release.html_url,
|
|
prerelease: release.prerelease ?? false,
|
|
}), {
|
|
status: 200,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Cache-Control': 'public, s-maxage=300, stale-while-revalidate=60, stale-if-error=3600',
|
|
'Access-Control-Allow-Origin': '*',
|
|
},
|
|
});
|
|
} catch {
|
|
return new Response(JSON.stringify({ error: 'fetch_failed' }), {
|
|
status: 502,
|
|
headers: { 'Content-Type': 'application/json' },
|
|
});
|
|
}
|
|
}
|