Files
worldmonitor/api/hackernews.js
Elie Habib 5d037c4132 Add tech variant with expanded global tech ecosystem data
- Add variant system (full/tech) with VITE_VARIANT env var
- Create tech-geo.ts with 465 entries:
  - 295 TECH_HQS (FAANG, unicorns across US, Europe, MENA, India, SEA, China, LATAM, Africa)
  - 112 ACCELERATORS (YC, Techstars, 500 Global, regional accelerators)
  - 38 STARTUP_HUBS (mega/major/emerging tiers)
  - 20 CLOUD_REGIONS (AWS, GCP, Azure, Cloudflare)
- Add map layers: startupHubs, cloudRegions, accelerators, techHQs
- Add tech-specific RSS feeds and panels
- Fix YouTube channel fallback IDs (Yahoo Finance, NASA TV, TBPN)
- MENA expansion: 50+ companies (UAE, Saudi, Egypt, Jordan)
- India: 40+ unicorns (Flipkart, PhonePe, Razorpay, etc)
- SEA: 25+ companies (Grab, GoTo, J&T Express, etc)
- LATAM: 35+ companies (Nubank, MercadoLibre, Bitso, etc)
2026-01-22 23:18:32 +04:00

74 lines
2.1 KiB
JavaScript

export const config = { runtime: 'edge' };
// Fetch Hacker News front page stories
// Uses official HackerNews Firebase API
export default async function handler(request) {
try {
const { searchParams } = new URL(request.url);
const storyType = searchParams.get('type') || 'top'; // top, new, best, ask, show, job
const limit = parseInt(searchParams.get('limit') || '30', 10);
// HackerNews official Firebase API
const storiesUrl = `https://hacker-news.firebaseio.com/v0/${storyType}stories.json`;
// Fetch story IDs
const storiesResponse = await fetch(storiesUrl, {
signal: AbortSignal.timeout(10000),
});
if (!storiesResponse.ok) {
throw new Error(`HackerNews API returned ${storiesResponse.status}`);
}
const storyIds = await storiesResponse.json();
const limitedIds = storyIds.slice(0, limit);
// Fetch story details in parallel (batch of 30)
const storyPromises = limitedIds.map(async (id) => {
const storyUrl = `https://hacker-news.firebaseio.com/v0/item/${id}.json`;
try {
const response = await fetch(storyUrl, {
signal: AbortSignal.timeout(5000),
});
if (response.ok) {
return await response.json();
}
return null;
} catch (error) {
console.error(`Failed to fetch story ${id}:`, error);
return null;
}
});
const stories = (await Promise.all(storyPromises)).filter(story => story !== null);
return new Response(JSON.stringify({
type: storyType,
stories: stories,
total: stories.length,
timestamp: new Date().toISOString()
}), {
status: 200,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'Cache-Control': 'public, max-age=300', // 5 min cache
},
});
} catch (error) {
return new Response(
JSON.stringify({
error: 'Failed to fetch Hacker News data',
message: error.message
}),
{
status: 500,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},
}
);
}
}