Files
worldmonitor/api/github-trending.js
Elie Habib c353cf2070 Reduce egress costs, add PWA support, fix Polymarket and Railway relay
Egress optimization:
- Add s-maxage + stale-while-revalidate to all API endpoints for Vercel CDN caching
- Add vercel.json with immutable caching for hashed assets
- Add gzip compression to sidecar responses >1KB
- Add gzip to Railway RSS responses (4 paths previously uncompressed)
- Increase polling intervals: markets/crypto 60s→120s, ETF/macro/stablecoins 60s→180s
- Remove hardcoded Railway URL from theater-posture.js (now env-var only)

PWA / Service Worker:
- Add vite-plugin-pwa with autoUpdate strategy
- Cache map tiles (CacheFirst), fonts (StaleWhileRevalidate), static assets
- NetworkOnly for all /api/* routes (real-time data must be fresh)
- Manual SW registration (web only, skip Tauri)
- Add offline fallback page
- Replace manual manifest with plugin-generated manifest

Polymarket fix:
- Route dev proxy through production Vercel (bypasses JA3 blocking)
- Add 4th fallback tier: production URL as absolute fallback

Desktop/Sidecar:
- Dual-backend cache (_upstash-cache.js): Redis cloud + in-memory+file desktop
- Settings window OK/Cancel redesign
- Runtime config and secret injection improvements
2026-02-14 19:53:04 +04:00

85 lines
2.6 KiB
JavaScript

export const config = { runtime: 'edge' };
// Fetch trending GitHub repositories
// Uses unofficial GitHub trending scraper API
export default async function handler(request) {
try {
const { searchParams } = new URL(request.url);
const language = searchParams.get('language') || 'python'; // python, javascript, typescript, etc.
const since = searchParams.get('since') || 'daily'; // daily, weekly, monthly
const spoken_language = searchParams.get('spoken_language') || ''; // en, zh, etc.
// Using GitHub trending API (unofficial)
// Alternative: https://gh-trending-api.herokuapp.com/repositories
const baseUrl = 'https://api.gitterapp.com/repositories';
const queryParams = new URLSearchParams({
language: language,
since: since,
});
if (spoken_language) {
queryParams.append('spoken_language_code', spoken_language);
}
const apiUrl = `${baseUrl}?${queryParams.toString()}`;
const response = await fetch(apiUrl, {
headers: {
'Accept': 'application/json',
'User-Agent': 'WorldMonitor/1.0 (Tech Tracker)',
},
signal: AbortSignal.timeout(10000), // 10 second timeout
});
if (!response.ok) {
// Fallback: try alternative API
const fallbackUrl = `https://gh-trending-api.herokuapp.com/repositories/${language}?since=${since}`;
const fallbackResponse = await fetch(fallbackUrl, {
headers: {
'Accept': 'application/json',
},
signal: AbortSignal.timeout(10000),
});
if (!fallbackResponse.ok) {
throw new Error(`GitHub trending API returned ${fallbackResponse.status}`);
}
const data = await fallbackResponse.json();
return new Response(JSON.stringify(data), {
status: 200,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'Cache-Control': 'public, max-age=1800, s-maxage=1800, stale-while-revalidate=300', // 30 min cache
},
});
}
const data = await response.json();
return new Response(JSON.stringify(data), {
status: 200,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'Cache-Control': 'public, max-age=1800, s-maxage=1800, stale-while-revalidate=300', // 30 min cache
},
});
} catch (error) {
return new Response(
JSON.stringify({
error: 'Failed to fetch GitHub trending data',
message: error.message
}),
{
status: 500,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},
}
);
}
}