railyard/apps/console/middleware.ts
caelum0x fe1b93e66d fix(railyard): RIT-OPS prepare toolgate-301 redirect, not deployed
railyard.ereboslab.com's Scribase project expired (plans/railyard.md "console
backend is gone"); add apps/console/middleware.ts that 301s the whole domain
to toolgate.scribase.com (path-preserving for the few paths real on both
hosts, else homepage) instead of rebuilding the console on a new temp
project. Confirmed it's served by a Cloudflare Worker (custom_domain route in
wrangler.jsonc), not Caddy, and that wrangler auth works now for this
account. typecheck + full test suite (167/167 + 3/3) still pass; no deploy
run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 20:01:13 +03:00

53 lines
2.2 KiB
TypeScript

import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
/**
* RIT-OPS (toolgate-301, 2026-11-30): this Worker's Scribase project was a
* 72h temp one (created 2026-10-27) that expired — auth and `/status/*` now
* 404 "unknown project" (plans/railyard.md, "railyard.ereboslab.com console
* backend is gone"). The console is a consumer site on an ereboslab
* subdomain (frozen, not a git./ritgram. exemption) and Toolgate
* (toolgate.scribase.com) has been canonical since 2026-11-12. Don't rebuild
* the console on a new temp project — redirect this whole domain to
* Toolgate instead, path-preserving only for the handful of public paths
* that exist on both this app's route tree and apps/toolgate's
* (crates/switchyard-server/src/lib.rs); everything else (console-only
* routes like /billing, /insights, /oidc/*, /auth/*, /device, /connect/ai,
* /rithub, /status/*) goes to the Toolgate homepage.
*
* Config only — not deployed yet. Deploying needs `wrangler deploy` from
* apps/console (see DEPLOY.md); wrangler auth was re-verified working
* 2026-11-30 (`npx wrangler whoami` → Subasiarhan3@gmail.com account, scopes
* include `workers (write)` + `workers_routes (write)`), so the earlier
* "wrangler auth dead" note in plans/kamiko.md is stale for this account.
*/
const TOOLGATE_ORIGIN = "https://toolgate.scribase.com";
// Exact paths real on both hosts today — keep the path; everything else
// (every console-only route) collapses to the Toolgate homepage.
const PRESERVED_PATHS = new Set<string>([
"/",
"/robots.txt",
"/sitemap.xml",
"/llms.txt",
"/llms-full.txt",
"/openapi.json",
]);
export function middleware(request: NextRequest) {
const { pathname, search } = request.nextUrl;
const target = new URL(TOOLGATE_ORIGIN);
if (PRESERVED_PATHS.has(pathname)) {
target.pathname = pathname;
target.search = search;
}
return NextResponse.redirect(target, 301);
}
// Run on every path, including "/", but skip Next's own internals so the
// Worker's static asset handling (favicons, _next/*) isn't dragged through
// a redirect loop before this can even match.
export const config = {
matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
};