PR Checks / Frontend Typecheck + Tests (pull_request) Successful in 1m15s
PR Checks / Backend Smoke (pull_request) Successful in 9s
PR Checks / Build Backend (no push) (pull_request) Successful in 20s
PR Checks / Build Frontend (no push) (pull_request) Successful in 1m21s
PR Checks / Build Pipeline (no push) (pull_request) Successful in 12s
PR Checks / AI Code Review (Claude) (pull_request) Successful in 1m39s
Both features ship dark. Neither is reachable in an environment where its flag is off, and every flag in this system starts off, so a deploy of this commit makes both disappear until someone turns them on deliberately. Two independent flags rather than one, which makes blog-on-about-off a reachable state. That state is the whole reason the change is larger than four notFound() calls: the blog leans on the About page for its author identity. The Person entity is anchored at /about#tudor, and that URL 404s while about_page is dark, so a post published in that state would claim an author resolving to nothing. Worse than having no named author. Both bylines fall back to unlinked text and the BlogPosting attributes to the publisher instead, so every combination of the two flags renders something correct. Gated: /about, /blog, /blog/[slug], the RSS feed, both footer links, and the matching content-sitemap entries. A sitemap must never advertise a URL that 404s. With both dark it emits a valid empty urlset rather than a 404, because robots.txt names it unconditionally. Not gated: /admin. Posts have to be writable before the blog is worth switching on, so flagging the panel would make the flag unflippable. getFlags takes a revalidate rather than always using the 300s constant. Reading a flag pins the calling route to the lowest revalidate among its fetches, and the footer links live in the root layout, so a naive gate there would have dropped every school and place page from a weekly cache to a 5-minute one. The layout passes 604800, the floor those routes already declare, and the build confirms all four SSG route families still prerender. The cost is one-way latency: pages follow a flip in minutes, footer links within a week. The e2e journeys follow the existing paired shape from the admission_distance flag: a lit journey and a dark one for each flag, reading state from whether /about and /blog respond rather than from /api/flags, which another journey asserts is not publicly reachable. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DXnXQKnPpZBBP61fBQiFkq
51 lines
1.9 KiB
TypeScript
51 lines
1.9 KiB
TypeScript
/**
|
|
* Reading feature flags.
|
|
*
|
|
* Server-side only. No flag value reaches the browser bundle, and there is no
|
|
* Unleash dependency in package.json — the SDK lives in FastAPI, which already
|
|
* owns every other piece of data this app renders.
|
|
*
|
|
* Flags are declared in backend/flags.py. A purely front-end flag still has to
|
|
* be declared there; it is a flat data edit, and the return is that one list
|
|
* answers "what flags exist" for the whole system.
|
|
*/
|
|
|
|
export type Flags = Record<string, boolean>;
|
|
|
|
/*
|
|
* Reading flags pins the calling route to this ISR floor: Next uses the LOWEST
|
|
* revalidate among a route's fetches to set the whole route's revalidation
|
|
* frequency. 300s matches what /school/[slug] already sits at, so a page that
|
|
* reads flags is no more dynamic than a school page already is.
|
|
*
|
|
* It is also what makes a flip propagate without a webhook: five minutes on
|
|
* school pages, an hour on place pages, against flags that flip monthly.
|
|
*/
|
|
export const FLAGS_REVALIDATE = 300;
|
|
|
|
const API = process.env.FASTAPI_URL || process.env.NEXT_PUBLIC_API_URL
|
|
|| 'http://localhost:8000/api';
|
|
|
|
/**
|
|
* Every flag and its value. Never throws: an unreadable flag is a dark one.
|
|
*
|
|
* `revalidate` is the caller's, because reading flags pins the whole route to
|
|
* the lowest revalidate among its fetches. Every SEO route here declares
|
|
* 604800; gating one at the 300s default would drop it from a weekly cache to
|
|
* a 5-minute one. Pass the route's own floor and gating costs it nothing.
|
|
*
|
|
* The trade is flag-flip latency: a route that revalidates weekly takes up to
|
|
* a week to notice a flip. Pass a smaller number where a flip must land fast.
|
|
*/
|
|
export async function getFlags(revalidate: number = FLAGS_REVALIDATE): Promise<Flags> {
|
|
try {
|
|
const res = await fetch(`${API}/flags`, {
|
|
next: { revalidate },
|
|
});
|
|
if (!res.ok) return {};
|
|
return await res.json();
|
|
} catch {
|
|
return {};
|
|
}
|
|
}
|