should be all good now (and added api status notifications)
Some checks failed
Deploy Backend / deploy (push) Successful in 3m38s
Deploy Website / deploy (push) Has been cancelled

This commit is contained in:
Lee 2024-10-16 08:15:11 +01:00
parent 1eed0e1e99
commit cb7143ed3d
5 changed files with 37 additions and 7 deletions

@ -12,6 +12,13 @@ export default class AppController {
}; };
} }
@Get("/health")
public async getHealth() {
return {
status: "OK",
};
}
@Get("/statistics") @Get("/statistics")
public async getStatistics() { public async getStatistics() {
return await AppService.getAppStatistics(); return await AppService.getAppStatistics();

@ -11,7 +11,11 @@ type ApiHealth = {
*/ */
export async function getApiHealth(url: string): Promise<ApiHealth> { export async function getApiHealth(url: string): Promise<ApiHealth> {
try { try {
await ky.get(url); await ky
.get(url, {
cache: "no-cache",
})
.json();
return { return {
online: true, online: true,
}; };

@ -1,3 +1,5 @@
import ky from "ky";
/** /**
* Checks if we're in production * Checks if we're in production
*/ */
@ -24,3 +26,17 @@ export function delay(ms: number) {
export function getPageFromRank(rank: number, itemsPerPage: number) { export function getPageFromRank(rank: number, itemsPerPage: number) {
return Math.floor(rank / itemsPerPage) + 1; 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 { Button } from "@/components/ui/button";
import Link from "next/link"; import Link from "next/link";
import ky from "ky";
import { config } from "../../../config"; import { config } from "../../../config";
import { AppStatistics } from "@ssr/common/types/backend/app-statistics"; import { AppStatistics } from "@ssr/common/types/backend/app-statistics";
import Statistic from "@/components/home/statistic"; 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 const dynamic = "force-dynamic"; // Always generate the page on load
export default async function HomePage() { export default async function HomePage() {
const statistics = await ky.get(config.siteApi + "/statistics").json<AppStatistics>(); const statistics = await kyFetch<AppStatistics>(config.siteApi + "/statistics");
return ( return (
<main className="flex flex-col items-center w-full gap-6 text-center"> <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> <p>ScoreSaber Reloaded is a website that allows you to track your ScoreSaber data over time.</p>
</div> </div>
{statistics && (
<div className="flex items-center flex-col"> <div className="flex items-center flex-col">
<p className="font-semibold">Site Statistics</p> <p className="font-semibold">Site Statistics</p>
<Statistic title="Total Tracked Players" value={statistics.trackedPlayers} /> <Statistic title="Total Tracked Players" value={statistics.trackedPlayers} />
</div> </div>
)}
<div className="flex gap-2 flex-wrap"> <div className="flex gap-2 flex-wrap">
<Link href="/search"> <Link href="/search">

@ -34,6 +34,7 @@ export function ApiHealth() {
title: `The API is now ${online ? "Online" : "Offline"}!`, title: `The API is now ${online ? "Online" : "Offline"}!`,
description: online ? "The API has recovered connectivity." : "The API has lost connectivity.", description: online ? "The API has recovered connectivity." : "The API has lost connectivity.",
variant: online ? "success" : "destructive", variant: online ? "success" : "destructive",
duration: 10_000, // 10 seconds
}); });
} }