Skip to content

Commit

Permalink
Cache ping data (#417)
Browse files Browse the repository at this point in the history
Cache ping data with NextJS data cache
  • Loading branch information
ngundotra authored Nov 20, 2024
1 parent 8a6f977 commit 1abc54f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/api/ping/[network]/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { fetch } from 'cross-fetch';
import { NextResponse } from 'next/server';

type Params = {
Expand All @@ -25,11 +24,12 @@ export async function GET(_request: Request, { params: { network } }: Params) {
const responses = await Promise.all(
PING_INTERVALS.map(interval =>
fetch(`https://www.validators.app/api/v1/ping-thing-stats/${network}.json?interval=${interval}`, {
cache: 'no-store',
headers: {
'Cache-Control': 'no-store, max-age=0',
Token: process.env.PING_API_KEY || '',
},
next: {
revalidate: 60,
},
})
)
);
Expand All @@ -43,7 +43,7 @@ export async function GET(_request: Request, { params: { network } }: Params) {

return NextResponse.json(data, {
headers: {
'Cache-Control': 'public, max-age=30',
'Cache-Control': 'no-store, max-age=0',
},
});
}

0 comments on commit 1abc54f

Please sign in to comment.