Skip to content

Commit

Permalink
sever render pages
Browse files Browse the repository at this point in the history
  • Loading branch information
kenny-io committed Jul 24, 2024
1 parent d21884c commit a62aeb2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 39 deletions.
3 changes: 1 addition & 2 deletions frontend/api/fetchstatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ async function fetchPrometheusData() {
const query = encodeURIComponent('Shardeum');
const url = process.env.NEXT_PUBLIC_PROMETHEUS_URL_RANGE + `?query=${query}&start=${start}&end=${end}&step=${step}`;
try {

const response = await fetch(url, {
next: {
revalidate: 5,
revalidate: 60,
},
});
if (!response.ok) {
Expand Down
40 changes: 3 additions & 37 deletions frontend/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,6 @@
import { Service, ServicesData } from "../../types/service";
async function fetchStatus(): Promise<ServicesData> {
const url = process.env.NEXT_PUBLIC_PROMETHEUS_URL || '';
const response = await fetch(url, {
next: {
revalidate: 5,
},
});
const jsonResponse = await response.json();
const services: Service[] = jsonResponse.data.result.map((item: any) => ({
name: item.metric.name,
status: {
value: parseInt(item.value[1], 10),
labels: item.metric,
},
}));

const latestServicesMap = services.reduce<Record<string, Service>>((acc, currentService) => {
const existingService = acc[currentService.name];
const existingTimestamp = existingService?.status.labels.timestamp
? parseInt(existingService.status.labels.timestamp, 10)
: 0;
const currentTimestamp = currentService.status.labels.timestamp
? parseInt(currentService.status.labels.timestamp, 10)
: 0;

if (!existingService || currentTimestamp > existingTimestamp) {
acc[currentService.name] = currentService;
}

return acc;
}, {});

const latestServices = Object.values(latestServicesMap);
return { services: latestServices };
}

import { Service } from "../../types/service";
import { fetchStatus } from "../../api";
export const dynamic = 'force-dynamic'
export default async function Home() {
const data = await fetchStatus()
const { services } = data;
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/app/uptime/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { fetchStatus } from "../../../api/fetchstatus";
import { Service } from "../../../types/service";

export const dynamic = 'force-dynamic'

export default async function Home() {
const data = await fetchStatus(60)
const { services } = data;
Expand Down

0 comments on commit a62aeb2

Please sign in to comment.