Skip to content

Commit 3838f3c

Browse files
authored
fix: handle missing TASTY_API_URL (#2282)
Skip tasty metrics fetch when TASTY_API_URL is not configured, allowing dev server to start without the environment variable.
1 parent ea286e1 commit 3838f3c

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

scripts/pullMetadata.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,31 @@ async function pullData() {
4242
fetchJson(CEXS_DATA_URL)
4343
.then((data) => data.cexs ?? [])
4444
.catch(() => []),
45-
fetch(`${process.env.TASTY_API_URL}/metrics?startAt=${startAt}&endAt=${endAt}&unit=day&type=url`, {
46-
headers: {
47-
Authorization: `Bearer ${process.env.TASTY_API_KEY}`
48-
}
49-
})
50-
.then((res) => res.json())
51-
.then((res) => {
52-
const tastyMetrics = {}
53-
const trendingRoutes = []
54-
let i = 0
55-
for (const xy of res) {
56-
if (i <= 20) {
57-
trendingRoutes.push([xy.x, xy.y])
45+
process.env.TASTY_API_URL
46+
? fetch(`${process.env.TASTY_API_URL}/metrics?startAt=${startAt}&endAt=${endAt}&unit=day&type=url`, {
47+
headers: {
48+
Authorization: `Bearer ${process.env.TASTY_API_KEY}`
5849
}
59-
tastyMetrics[xy.x] = xy.y
60-
i++
61-
}
62-
return { tastyMetrics, trendingRoutes }
63-
})
64-
.catch((e) => {
65-
console.log('Error fetching tasty metrics', e)
66-
return { tastyMetrics: {}, trendingRoutes: [] }
67-
})
50+
})
51+
.then((res) => res.json())
52+
.then((res) => {
53+
const tastyMetrics = {}
54+
const trendingRoutes = []
55+
let i = 0
56+
for (const xy of res) {
57+
if (i <= 20) {
58+
trendingRoutes.push([xy.x, xy.y])
59+
}
60+
tastyMetrics[xy.x] = xy.y
61+
i++
62+
}
63+
return { tastyMetrics, trendingRoutes }
64+
})
65+
.catch((e) => {
66+
console.log('Error fetching tasty metrics', e)
67+
return { tastyMetrics: {}, trendingRoutes: [] }
68+
})
69+
: Promise.resolve({ tastyMetrics: {}, trendingRoutes: [] })
6870
])
6971

7072
if (!fs.existsSync(CACHE_DIR)) {

0 commit comments

Comments
 (0)