| 1 | export async function getStarCount(): Promise<number | undefined> { |
| 2 | try { |
| 3 | const response = await fetch( |
| 4 | `https://api.github.com/repos/triggerdotdev/jsonhero-web`, |
| 5 | { |
| 6 | headers: { |
| 7 | accept: "application/json", |
| 8 | "user-agent": |
| 9 | "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36", |
| 10 | }, |
| 11 | cf: { |
| 12 | cacheEverything: true, |
| 13 | cacheTtlByStatus: { |
| 14 | "200-299": 300, |
| 15 | "400-499": 5, |
| 16 | "500-599": 0, |
| 17 | }, |
| 18 | }, |
| 19 | } |
| 20 | ); |
| 21 | |
| 22 | if (!response.ok) { |
| 23 | console.error(`Could not fetch star count: ${response.statusText}`); |
| 24 | |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | const data = await response.json(); |
| 29 | return data.stargazers_count; |
| 30 | } catch (error) { |
| 31 | console.error(error); |
| 32 | return; |
| 33 | } |
| 34 | } |