should be all good now (and added api status notifications)
This commit is contained in:
parent
1eed0e1e99
commit
cb7143ed3d
@ -12,6 +12,13 @@ export default class AppController {
|
||||
};
|
||||
}
|
||||
|
||||
@Get("/health")
|
||||
public async getHealth() {
|
||||
return {
|
||||
status: "OK",
|
||||
};
|
||||
}
|
||||
|
||||
@Get("/statistics")
|
||||
public async getStatistics() {
|
||||
return await AppService.getAppStatistics();
|
||||
|
@ -11,7 +11,11 @@ type ApiHealth = {
|
||||
*/
|
||||
export async function getApiHealth(url: string): Promise<ApiHealth> {
|
||||
try {
|
||||
await ky.get(url);
|
||||
await ky
|
||||
.get(url, {
|
||||
cache: "no-cache",
|
||||
})
|
||||
.json();
|
||||
return {
|
||||
online: true,
|
||||
};
|
||||
|
@ -1,3 +1,5 @@
|
||||
import ky from "ky";
|
||||
|
||||
/**
|
||||
* Checks if we're in production
|
||||
*/
|
||||
@ -24,3 +26,17 @@ export function delay(ms: number) {
|
||||
export function getPageFromRank(rank: number, itemsPerPage: number) {
|
||||
return Math.floor(rank / itemsPerPage) + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches data from the given url.
|
||||
*
|
||||
* @param url the url to fetch
|
||||
*/
|
||||
export async function kyFetch<T>(url: string): Promise<T | undefined> {
|
||||
try {
|
||||
return await ky.get<T>(url).json();
|
||||
} catch (error) {
|
||||
console.error(`Error fetching data from ${url}:`, error);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
import { Button } from "@/components/ui/button";
|
||||
import Link from "next/link";
|
||||
import ky from "ky";
|
||||
import { config } from "../../../config";
|
||||
import { AppStatistics } from "@ssr/common/types/backend/app-statistics";
|
||||
import Statistic from "@/components/home/statistic";
|
||||
import { kyFetch } from "@ssr/common/utils/utils";
|
||||
|
||||
export const dynamic = "force-dynamic"; // Always generate the page on load
|
||||
|
||||
export default async function HomePage() {
|
||||
const statistics = await ky.get(config.siteApi + "/statistics").json<AppStatistics>();
|
||||
const statistics = await kyFetch<AppStatistics>(config.siteApi + "/statistics");
|
||||
|
||||
return (
|
||||
<main className="flex flex-col items-center w-full gap-6 text-center">
|
||||
@ -21,10 +21,12 @@ export default async function HomePage() {
|
||||
<p>ScoreSaber Reloaded is a website that allows you to track your ScoreSaber data over time.</p>
|
||||
</div>
|
||||
|
||||
{statistics && (
|
||||
<div className="flex items-center flex-col">
|
||||
<p className="font-semibold">Site Statistics</p>
|
||||
<Statistic title="Total Tracked Players" value={statistics.trackedPlayers} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex gap-2 flex-wrap">
|
||||
<Link href="/search">
|
||||
|
@ -34,6 +34,7 @@ export function ApiHealth() {
|
||||
title: `The API is now ${online ? "Online" : "Offline"}!`,
|
||||
description: online ? "The API has recovered connectivity." : "The API has lost connectivity.",
|
||||
variant: online ? "success" : "destructive",
|
||||
duration: 10_000, // 10 seconds
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user