generated from nhcarrigan/template
a36c8e72a5
## Summary
- Add comprehensive try/catch error handling across all API routes, middleware, and the Hono global error handler, piping every unhandled error to the `@nhcarrigan/logger` service to prevent silent crashes and unhandled Promise rejections
- Add a `logError` utility on the frontend that forwards errors through the overridden `console.error` to the backend telemetry endpoint; apply it to every silent `catch {}` block in the game context, sound, notification, and clipboard utilities, and wrap the React tree in an `ErrorBoundary`
- Add Plausible analytics, Open Graph + Twitter Card meta tags, Tree-Nation widget, and Google Ads to `index.html`
- Make the game sidebar sticky with a `--resource-bar-height` CSS custom property offset so it stays viewport-height without overlapping the resource bar; reset sticky behaviour in the mobile responsive override
## Test plan
- [ ] Lint passes: `pnpm lint`
- [ ] Build passes: `pnpm build`
- [ ] Verify errors thrown in API routes appear in the logger service rather than crashing the process
- [ ] Verify frontend errors appear in the `/api/fe/error` backend log
- [ ] Verify Open Graph tags render correctly when sharing the URL
- [ ] Verify Plausible analytics fires on page load
- [ ] Verify Tree-Nation badge renders in the sidebar
- [ ] Verify sidebar stays fixed while the main content scrolls on desktop
- [ ] Verify mobile layout is unaffected
✨ This issue was created with help from Hikari~ 🌸
Reviewed-on: #44
Co-authored-by: Hikari <hikari@nhcarrigan.com>
Co-committed-by: Hikari <hikari@nhcarrigan.com>
71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
/**
|
|
* @file About route providing API version and release information.
|
|
* @copyright nhcarrigan
|
|
* @license Naomi's Public License
|
|
* @author Naomi Carrigan
|
|
*/
|
|
/* eslint-disable stylistic/max-len -- URL cannot be shortened */
|
|
/* eslint-disable require-atomic-updates -- Simple cache; race condition is acceptable */
|
|
import { Hono } from "hono";
|
|
import { logger } from "../services/logger.js";
|
|
import type { AboutResponse, GiteaRelease } from "@elysium/types";
|
|
|
|
// eslint-disable-next-line capitalized-comments -- v8 ignore
|
|
/* v8 ignore next -- @preserve */
|
|
const apiVersion = process.env.npm_package_version ?? "unknown";
|
|
|
|
const giteaReleasesUrl = "https://git.nhcarrigan.com/api/v1/repos/nhcarrigan/elysium/releases";
|
|
const cacheTtlMs = 5 * 60 * 1000;
|
|
|
|
interface ReleasesCache {
|
|
data: Array<GiteaRelease>;
|
|
timestamp: number;
|
|
}
|
|
|
|
let releasesCache: ReleasesCache = { data: [], timestamp: 0 };
|
|
|
|
const fetchReleases = async(): Promise<Array<GiteaRelease>> => {
|
|
const now = Date.now();
|
|
if (releasesCache.data.length > 0 && now - releasesCache.timestamp < cacheTtlMs) {
|
|
return releasesCache.data;
|
|
}
|
|
try {
|
|
const response = await fetch(giteaReleasesUrl);
|
|
if (!response.ok) {
|
|
return releasesCache.data;
|
|
}
|
|
const rawData: unknown = await response.json();
|
|
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- External API response */
|
|
const data = rawData as Array<GiteaRelease>;
|
|
releasesCache = { data: data, timestamp: now };
|
|
return releasesCache.data;
|
|
} catch {
|
|
return releasesCache.data;
|
|
}
|
|
};
|
|
|
|
const aboutRouter = new Hono();
|
|
|
|
aboutRouter.get("/", async(context) => {
|
|
try {
|
|
const releases = await fetchReleases();
|
|
const body: AboutResponse = {
|
|
apiVersion,
|
|
releases,
|
|
};
|
|
return context.json(body);
|
|
// eslint-disable-next-line capitalized-comments -- v8 ignore
|
|
/* v8 ignore next 9 -- @preserve */
|
|
} catch (error) {
|
|
void logger.error(
|
|
"about",
|
|
error instanceof Error
|
|
? error
|
|
: new Error(String(error)),
|
|
);
|
|
return context.json({ error: "Internal server error" }, 500);
|
|
}
|
|
});
|
|
|
|
export { aboutRouter };
|