mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-20 13:07:57 +09:00
feat: serve the requests board on requests.nomadkaraoke.com itself (#1193)
## Summary `requests.nomadkaraoke.com` used to 302 to `gen.nomadkaraoke.com/en/requests`, so the short link couldn't be copied out of a mobile address bar (Andrew pastes it into YouTube comment replies). Now the board is served on the vanity host itself. - **New Worker `requests-host`** (`infrastructure/cloudflare/requests-host/`): `/` serves gen's `/en/requests/` (query kept), paths with an extension are proxied from gen, and every other path 302s to the same path on gen. - **Pulumi (already applied):** Worker route `requests.nomadkaraoke.com/*`; old redirect rule removed; DNS comment updated. - **Tenant detection:** `requests` added to the non-tenant subdomains. The browser and Pages Function now share one list (`frontend/lib/edge/nonTenantSubdomains.ts`); the browser copy had drifted and was missing `requests`. Backend list updated to match. - **Board "Make it yourself"** goes to `gen.nomadkaraoke.com/app` when on the vanity host. - **Docs:** runbook rewritten, including why a Pages custom domain didn't work. Attaching the domain bypassed zone redirect rules and served the gen homepage for ~3 min before rollback. ## Testing - `node --test infrastructure/cloudflare/requests-host/`: 4 pass - Jest tenant + new non-tenant list tests: pass. Backend `test_tenant_middleware.py`: 36 pass - `make test`: 6465 pass. 8 fail in `test_emulator_integration.py`, and the same 8 fail on a clean `origin/main` checkout (pre-existing, env-related) - New prod E2E `e2e/production/requests-vanity-host.spec.ts`: board at `/` with no redirect and the API working, other paths 302 to gen. The pass/fail status of the "not a tenant" check (still sends `X-Tenant-ID: requests` until this frontend deploys) is listed below. - Manual browser check on prod: URL stays `requests.nomadkaraoke.com/?utm_source=…`, board renders, no console errors | Prod E2E check | Before this deploy | |---|---| | serves board at `/` | ✅ | | other paths → gen | ✅ | | not treated as tenant | ❌ expected, fixed by this PR | Local CodeRabbit review done (1 minor doc finding, fixed). @coderabbitai ignore 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016FYpoNVXzJzqKFaowqpwxr --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1344a086da
commit
b02cce3cc7
18 files changed
+266
-61
No files matched your search
@@ -36,8 +36,9 @@ IS_PRODUCTION = os.environ.get("ENV", "").lower() == "production" or \
|
||||
bool(os.environ.get("K_SERVICE"))
|
||||
|
||||
|
||||
# Known non-tenant subdomains that should be treated as default Nomad Karaoke
|
||||
NON_TENANT_SUBDOMAINS = {"gen", "api", "www", "buy", "admin", "app", "beta"}
|
||||
# Known non-tenant subdomains that should be treated as default Nomad Karaoke.
|
||||
# Mirror of frontend/lib/edge/nonTenantSubdomains.ts ("requests" = voting-board host).
|
||||
NON_TENANT_SUBDOMAINS = {"gen", "api", "www", "buy", "admin", "app", "beta", "requests"}
|
||||
|
||||
|
||||
class TenantMiddleware(BaseHTTPMiddleware):
|
||||
|
||||
@@ -29,7 +29,8 @@ into paying [gen.nomadkaraoke.com](https://gen.nomadkaraoke.com) customers over
|
||||
## Where it lives
|
||||
|
||||
- **Public URL to share / link:** **https://requests.nomadkaraoke.com**
|
||||
(redirects to the board; this is the clean vanity link to put in YouTube descriptions, socials, etc.)
|
||||
(serves the board on that host, so the short URL stays in the address bar and can be copied
|
||||
on mobile; put it in YouTube descriptions/replies, socials, etc.)
|
||||
- Also directly reachable at `https://gen.nomadkaraoke.com/en/requests` (any of the 33 locales:
|
||||
`/es/requests`, `/de/requests`, …).
|
||||
|
||||
@@ -94,7 +95,7 @@ the same KaraokeNerds check the normal job-submission flow uses runs at two poin
|
||||
## How it works (technical, brief)
|
||||
|
||||
- **Frontend:** a route in the gen Next.js app (`frontend/app/[locale]/requests/`), fully translated
|
||||
to 33 locales. `requests.nomadkaraoke.com` is a Cloudflare redirect to it (see
|
||||
to 33 locales. `requests.nomadkaraoke.com` serves it via the `requests-host` Worker (see
|
||||
`docs/runbooks/requests-subdomain-cloudflare.md`).
|
||||
- **Auth:** reuses gen's passwordless magic-link system. Board sign-in sends
|
||||
`purpose="requests_board"`, which creates an identity **without** granting a welcome credit and
|
||||
|
||||
@@ -1,47 +1,59 @@
|
||||
# Wiring `requests.nomadkaraoke.com` → the voting board (Cloudflare)
|
||||
# `requests.nomadkaraoke.com` → the voting board (Cloudflare)
|
||||
|
||||
The public voting board is a route in the gen Next.js app: it deploys automatically with
|
||||
the `karaoke-gen` Cloudflare Pages project and is reachable at
|
||||
`https://gen.nomadkaraoke.com/en/requests` the moment this PR merges.
|
||||
The public voting board is a static route in the gen Next.js build
|
||||
(`https://gen.nomadkaraoke.com/en/requests/`). Since 2026-10-19 it is **served on**
|
||||
`requests.nomadkaraoke.com` itself, not redirected, so the short URL stays in the address bar
|
||||
(Andrew copies it from his phone into YouTube comment replies).
|
||||
|
||||
To make the vanity URL `requests.nomadkaraoke.com` (the thing we link from every YouTube
|
||||
description) resolve to the board, add a Cloudflare **redirect** — the same pattern the
|
||||
referral interstitial uses (`nomadkaraoke.com/r/CODE` → gen). This is **not** in Pulumi;
|
||||
`nomadkaraoke.com` DNS + rules are managed directly via the Cloudflare API/dashboard.
|
||||
## How it works
|
||||
|
||||
**Do this at SHIP time (after the PR is merged and Pages has deployed the `/requests`
|
||||
route)** — otherwise the redirect points at a 404 until the deploy lands.
|
||||
| Piece | Where |
|
||||
|---|---|
|
||||
| `requests` CNAME → `gen.nomadkaraoke.com`, proxied | Pulumi, `infrastructure/cloudflare/dns.py` |
|
||||
| Worker route `requests.nomadkaraoke.com/*` → `requests-host` | Pulumi, `infrastructure/cloudflare/pages_workers.py` |
|
||||
| Worker script `requests-host` | `infrastructure/cloudflare/requests-host/worker.js`, deployed by `deploy.sh` |
|
||||
|
||||
## Steps (dashboard — simplest, ~2 min)
|
||||
The Worker:
|
||||
|
||||
1. **DNS**: Cloudflare → `nomadkaraoke.com` → DNS → add a **proxied** (orange-cloud) record
|
||||
so the hostname exists at the edge and rules can match it:
|
||||
- Type `CNAME`, Name `requests`, Target `gen.nomadkaraoke.com`, Proxy **ON**.
|
||||
2. **Redirect Rule**: Rules → Redirect Rules → Create:
|
||||
- When incoming requests match: `Hostname` `equals` `requests.nomadkaraoke.com`
|
||||
- Then: Static redirect, URL `https://gen.nomadkaraoke.com/en/requests`, status **302**,
|
||||
preserve query string OFF.
|
||||
- `/` → fetches gen `/en/requests/` and returns it (query string kept, e.g. `utm_*`).
|
||||
- paths with a file extension (`/_next/*`, fonts, icons, `sw.js`, RSC `.txt`) → proxied from gen.
|
||||
- any other page path → 302 to the same path on gen, so the app never runs on this origin.
|
||||
|
||||
That's it — `requests.nomadkaraoke.com` now lands users on the board. (302 not 301 so we can
|
||||
later swap to a true custom-domain host without a cached permanent redirect fighting us.)
|
||||
The frontend treats `requests` as a non-tenant subdomain (`frontend/lib/edge/nonTenantSubdomains.ts`,
|
||||
`backend/middleware/tenant.py`), and the board's "Make it yourself" button leaves for
|
||||
`gen.nomadkaraoke.com/app` when on this host. Board sign-in magic links still land on gen
|
||||
(`/en/auth/verify` → `/requests`), so a user who signs in ends up on the gen copy of the board.
|
||||
|
||||
## Changing it
|
||||
|
||||
```bash
|
||||
cd infrastructure/cloudflare/requests-host
|
||||
node --test . # unit tests
|
||||
set -a; source ../../../../.envrc; set +a # workspace .envrc (Nomad CF account)
|
||||
./deploy.sh # upload script
|
||||
```
|
||||
|
||||
Route/DNS changes go through `pulumi up` in `infrastructure/cloudflare/`.
|
||||
|
||||
## Verify
|
||||
|
||||
From the repo root:
|
||||
|
||||
```bash
|
||||
curl -sI https://requests.nomadkaraoke.com | grep -i "location\|HTTP/"
|
||||
# expect: 302 + location: https://gen.nomadkaraoke.com/en/requests
|
||||
curl -sI https://requests.nomadkaraoke.com/ # 200, text/html, no location header
|
||||
curl -sI https://requests.nomadkaraoke.com/en/app/ # 302 → https://gen.nomadkaraoke.com/en/app/
|
||||
cd frontend && npx playwright test requests-vanity-host.spec.ts --config=playwright.production.config.ts
|
||||
```
|
||||
|
||||
Then open it in a browser and confirm the board renders and a magic-link sign-in works.
|
||||
## Don't: Pages custom domain + rewrite rule
|
||||
|
||||
## Later upgrade (optional, keeps the vanity host in the address bar)
|
||||
Tried 2026-10-19: attaching `requests.nomadkaraoke.com` as a custom domain on the `karaoke-gen`
|
||||
Pages project made Cloudflare serve the gen **homepage** there, ignoring the zone redirect rule.
|
||||
(The Pulumi token also lacks Transform Rules permission.) Rolled back within ~3 minutes.
|
||||
The Worker avoids both problems.
|
||||
|
||||
Attach `requests.nomadkaraoke.com` as a **custom domain** on the `karaoke-gen` Pages project
|
||||
and add a host-aware root rewrite (`/` on that host → `/en/requests`). `requests` is already in
|
||||
the `nonTenantSubdomains` allow-list in `frontend/functions/[[path]].ts`, so it will not be
|
||||
mistaken for a white-label tenant. Not needed for Phase 1 — the redirect above is sufficient.
|
||||
## Rollback
|
||||
|
||||
## Record
|
||||
|
||||
Log any DNS/rule change made here (and in the workspace infra notes) per the standing rule that
|
||||
Cloudflare API/dashboard changes leave no trace in code.
|
||||
Restore the old redirect: remove the Worker route in `pages_workers.py` and re-add a
|
||||
`http_request_dynamic_redirect` rule `(http.host eq "requests.nomadkaraoke.com")` → 302
|
||||
`https://gen.nomadkaraoke.com/en/requests` in `rulesets.py`, then `pulumi up`.
|
||||
@@ -21,6 +21,7 @@ import { CommunityVersionBanner } from '@/components/job/CommunityVersionBanner'
|
||||
import type { BoardResponse, SongRequestPublic } from '@/lib/types';
|
||||
|
||||
const BOARD_PURPOSE = 'requests_board';
|
||||
const REQUESTS_HOST = 'requests.nomadkaraoke.com';
|
||||
|
||||
export function RequestsBoardClient() {
|
||||
const t = useTranslations('requests');
|
||||
@@ -168,6 +169,12 @@ export function RequestsBoardClient() {
|
||||
/* non-blocking — the create flow still works, credit can be claimed later */
|
||||
}
|
||||
}
|
||||
// requests.nomadkaraoke.com serves only the board (edge rules send every other path
|
||||
// to gen), so leave the vanity host instead of client-routing the app onto it.
|
||||
if (window.location.hostname === REQUESTS_HOST) {
|
||||
window.location.href = 'https://gen.nomadkaraoke.com/app';
|
||||
return;
|
||||
}
|
||||
router.push('/app');
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
/**
|
||||
* requests.nomadkaraoke.com serves the voting board on its own host (2026-10-19).
|
||||
*
|
||||
* The link we paste in YouTube replies/descriptions must stay in the address bar so it can
|
||||
* be copied back out on mobile. Cloudflare edge rules (infrastructure/cloudflare/rulesets.py)
|
||||
* rewrite `/` to the static /en/requests/ page and redirect every other page path to gen.
|
||||
*
|
||||
* Usage:
|
||||
* npx playwright test requests-vanity-host.spec.ts --config=playwright.production.config.ts
|
||||
*/
|
||||
|
||||
const REQUESTS_ORIGIN = 'https://requests.nomadkaraoke.com';
|
||||
|
||||
test.describe('requests.nomadkaraoke.com vanity host', () => {
|
||||
test('serves the board at / without redirecting away', async ({ page }) => {
|
||||
// The board's data call to the API must succeed from this origin.
|
||||
const boardResponse = page.waitForResponse(
|
||||
(r) => r.url().includes('/api/requests-board/') && r.request().method() === 'GET',
|
||||
{ timeout: 30_000 },
|
||||
);
|
||||
const response = await page.goto(`${REQUESTS_ORIGIN}/?utm_source=e2e`);
|
||||
expect(response?.status()).toBe(200);
|
||||
// No redirect chain: the first response is the page itself.
|
||||
expect(response?.request().redirectedFrom()).toBeNull();
|
||||
|
||||
await expect(page.getByRole('heading', { level: 1 })).toBeVisible({ timeout: 30_000 });
|
||||
expect((await boardResponse).ok()).toBe(true);
|
||||
|
||||
const url = new URL(page.url());
|
||||
expect(url.host).toBe('requests.nomadkaraoke.com');
|
||||
expect(url.pathname).toBe('/');
|
||||
expect(url.searchParams.get('utm_source')).toBe('e2e');
|
||||
});
|
||||
|
||||
test('is not treated as a white-label tenant', async ({ page }) => {
|
||||
const tenantHeaders: string[] = [];
|
||||
page.on('request', (req) => {
|
||||
const tenant = req.headers()['x-tenant-id'];
|
||||
if (tenant) tenantHeaders.push(tenant);
|
||||
});
|
||||
await page.goto(`${REQUESTS_ORIGIN}/`);
|
||||
await expect(page.getByRole('heading', { level: 1 })).toBeVisible({ timeout: 30_000 });
|
||||
expect(tenantHeaders).toEqual([]);
|
||||
});
|
||||
|
||||
test('other page paths redirect to gen', async ({ request }) => {
|
||||
const response = await request.get(`${REQUESTS_ORIGIN}/en/app/`, { maxRedirects: 0 });
|
||||
expect([301, 302]).toContain(response.status());
|
||||
expect(response.headers()['location']).toBe('https://gen.nomadkaraoke.com/en/app/');
|
||||
});
|
||||
});
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
import { getTenantConfig } from "../lib/edge/tenantConfigCache"
|
||||
import { injectTenantIntoHtml } from "../lib/edge/tenantHtmlInjection"
|
||||
import { NON_TENANT_SUBDOMAINS } from "../lib/edge/nonTenantSubdomains"
|
||||
|
||||
/**
|
||||
* Extract tenant ID from hostname.
|
||||
@@ -20,14 +21,13 @@ import { injectTenantIntoHtml } from "../lib/edge/tenantHtmlInjection"
|
||||
*/
|
||||
function extractTenantFromHost(hostname: string): string | null {
|
||||
const parts = hostname.toLowerCase().split(".")
|
||||
const nonTenantSubdomains = ["gen", "api", "www", "buy", "admin", "app", "beta", "requests"]
|
||||
|
||||
// Accept exactly 3 parts (tenant.nomadkaraoke.com)
|
||||
// or exactly 4 parts where second is "gen" (tenant.gen.nomadkaraoke.com)
|
||||
const isThreePart = parts.length === 3 && parts[1] === "nomadkaraoke" && parts[2] === "com"
|
||||
const isFourPart = parts.length === 4 && parts[1] === "gen" && parts[2] === "nomadkaraoke" && parts[3] === "com"
|
||||
|
||||
if ((isThreePart || isFourPart) && !nonTenantSubdomains.includes(parts[0])) {
|
||||
if ((isThreePart || isFourPart) && !NON_TENANT_SUBDOMAINS.includes(parts[0])) {
|
||||
return parts[0]
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { NON_TENANT_SUBDOMAINS } from "../edge/nonTenantSubdomains"
|
||||
|
||||
describe("NON_TENANT_SUBDOMAINS", () => {
|
||||
it("treats the voting-board vanity host as Nomad Karaoke, not a tenant", () => {
|
||||
// requests.nomadkaraoke.com serves the board directly; if it were detected as a
|
||||
// tenant the page would send X-Tenant-ID: requests and try to load tenant branding.
|
||||
expect(NON_TENANT_SUBDOMAINS).toContain("requests")
|
||||
})
|
||||
|
||||
it("matches the backend list in backend/middleware/tenant.py", () => {
|
||||
expect([...NON_TENANT_SUBDOMAINS].sort()).toEqual(
|
||||
["admin", "api", "app", "beta", "buy", "gen", "requests", "www"],
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* First-level subdomains of nomadkaraoke.com that are Nomad Karaoke itself, never a
|
||||
* white-label tenant. Shared by the browser (lib/tenant.ts) and the Pages Function
|
||||
* (functions/[[path]].ts) so the two lists can't drift. Mirror any change in
|
||||
* backend/middleware/tenant.py NON_TENANT_SUBDOMAINS.
|
||||
*
|
||||
* "requests" is the voting-board vanity host (requests.nomadkaraoke.com).
|
||||
*/
|
||||
export const NON_TENANT_SUBDOMAINS: readonly string[] = [
|
||||
"gen",
|
||||
"api",
|
||||
"www",
|
||||
"buy",
|
||||
"admin",
|
||||
"app",
|
||||
"beta",
|
||||
"requests",
|
||||
]
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { create } from "zustand"
|
||||
import { API_BASE_URL } from "./api"
|
||||
import { NON_TENANT_SUBDOMAINS } from "./edge/nonTenantSubdomains"
|
||||
|
||||
// Types for tenant configuration
|
||||
export interface TenantBranding {
|
||||
@@ -142,8 +143,6 @@ function detectTenantFromUrl(): string | null {
|
||||
// - {tenant}.gen.nomadkaraoke.com (4 parts with "gen" as second)
|
||||
if (hostname.includes("nomadkaraoke.com")) {
|
||||
const parts = hostname.split(".")
|
||||
// Skip known non-tenant subdomains
|
||||
const nonTenantSubdomains = ["gen", "api", "www", "buy", "admin", "app", "beta"]
|
||||
|
||||
// Accept exactly 3 parts (tenant.nomadkaraoke.com)
|
||||
// or exactly 4 parts where second is "gen" (tenant.gen.nomadkaraoke.com)
|
||||
@@ -151,7 +150,7 @@ function detectTenantFromUrl(): string | null {
|
||||
parts.length === 3 ||
|
||||
(parts.length === 4 && parts[1] === "gen")
|
||||
|
||||
if (isValidPattern && !nonTenantSubdomains.includes(parts[0])) {
|
||||
if (isValidPattern && !NON_TENANT_SUBDOMAINS.includes(parts[0])) {
|
||||
return parts[0]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ only app-specific stacks (e.g. karaoke-decide's Cloud Run + its API-proxy Worker
|
||||
| `email_routing.py` | Gmail destination address; Email Routing enablement (**protected**), catch-all and `google@` rules for nomadkaraoke.com, nomadkaroke.com, karaokehunt.com |
|
||||
| `tunnels.py` | `nomad-kjbox` (NomadPC: sing, kjbox, kjssh, kjvnc) and `nomad-hf2` (fiverrbot) tunnels (**protected**) + ingress |
|
||||
| `access.py` | Zero Trust org (**protected**), one-time-PIN + Google IdPs (Google OAuth client in GCP `nomadkaraoke`, secret in Pulumi config `googleOauthClientSecret`), `claude-code-kjbox` service token, reusable policies and the KJ Controller / FiverrBot noVNC apps |
|
||||
| `pages_workers.py` | Pages projects `karaoke-gen` + `karaoke-gen-tenant`, `gen.nomadkaraoke.com` Pages domain, nomadkaraoke.com/www Worker custom domains, `create.karaokehunt.com/*` route |
|
||||
| `pages_workers.py` | Pages projects `karaoke-gen` + `karaoke-gen-tenant`, `gen.nomadkaraoke.com` Pages domain, nomadkaraoke.com/www Worker custom domains, `create.karaokehunt.com/*` and `requests.nomadkaraoke.com/*` routes |
|
||||
|
||||
All resource IDs (`ids.py`) are non-secret. Removing a non-protected resource from code deletes it
|
||||
on the next `pulumi up`, and `pulumi preview` always shows that first.
|
||||
@@ -30,7 +30,7 @@ on the next `pulumi up`, and `pulumi preview` always shows that first.
|
||||
| `api` / `api-edge-test` DNS, nomadkaraoke.com `http_request_firewall_custom` / `http_ratelimit` / `http_request_late_transform` phases, `security_level` | GCP platform project, `infrastructure/modules/edge_security.py` |
|
||||
| Tenant portal CNAMEs (`<tenant>.nomadkaraoke.com`) and `karaoke-gen-tenant` custom domains | Created at runtime by `backend/services/tenant_domain_service.py` |
|
||||
| `decide.nomadkaraoke.com/api/*` route + `karaoke-decide-api-proxy` Worker | karaoke-decide's Pulumi stack |
|
||||
| Worker/Pages **code** deploys | gen CI (`wrangler pages deploy`), public-website Workers Builds, `karaokehunt-interceptor/deploy.sh` (its route + DNS "ensure" steps match what's declared here) |
|
||||
| Worker/Pages **code** deploys | gen CI (`wrangler pages deploy`), public-website Workers Builds, `karaokehunt-interceptor/deploy.sh` (its route + DNS "ensure" steps match what's declared here), `requests-host/deploy.sh` (script only) |
|
||||
| Read-only DNS records (Email Routing MX/DKIM, Worker custom-domain AAAAs) | Owned by Email Routing / Workers custom domains |
|
||||
| karaokehunt.com `http_config_settings` ("SSL for create.karaokehunt.com", "Disable challenge for create API") | Dashboard. pulumi-cloudflare 6.22.1 drops `set_config bic:false`, so every refresh fails |
|
||||
| Tunnel connector tokens / cloudflared processes | NomadPC systemd `cloudflared-nomad`, hf2 `~/nomad-tunnel` compose |
|
||||
|
||||
@@ -379,7 +379,7 @@ dns_nomadkaraoke_com_pm_bounces_cname = cloudflare.DnsRecord("dns-nomadkaraoke-c
|
||||
type="CNAME",
|
||||
zone_id=ZONE_IDS["nomadkaraoke.com"])
|
||||
dns_nomadkaraoke_com_requests_cname = cloudflare.DnsRecord("dns-nomadkaraoke-com-requests-cname",
|
||||
comment="Requests voting board vanity subdomain → redirect rule to gen/en/requests (added by Claude, PR #975)",
|
||||
comment="Voting board host: requests-host Worker route serves gen /en/requests/ here",
|
||||
content="gen.nomadkaraoke.com",
|
||||
name="requests.nomadkaraoke.com",
|
||||
proxied=True,
|
||||
|
||||
@@ -12,6 +12,11 @@ worker_route_create_karaokehunt_com = cloudflare.WorkersRoute("worker-route-crea
|
||||
pattern="create.karaokehunt.com/*",
|
||||
script="karaokehunt-interceptor",
|
||||
zone_id=ZONE_IDS["karaokehunt.com"])
|
||||
# Serves the voting board on requests.nomadkaraoke.com itself (script: requests-host/, deploy.sh).
|
||||
worker_route_requests_nomadkaraoke_com = cloudflare.WorkersRoute("worker-route-requests-nomadkaraoke-com",
|
||||
pattern="requests.nomadkaraoke.com/*",
|
||||
script="requests-host",
|
||||
zone_id=ZONE_IDS["nomadkaraoke.com"])
|
||||
pages_karaoke_gen_tenant = cloudflare.PagesProject("pages-karaoke-gen-tenant",
|
||||
account_id=ACCOUNT_ID,
|
||||
build_config={
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
# Upload the requests-host Worker script (idempotent). See worker.js for what it does.
|
||||
#
|
||||
# Only the script is deployed here; its route (requests.nomadkaraoke.com/*) and the proxied
|
||||
# requests CNAME are declared in the nomad-cloudflare Pulumi stack (../pages_workers.py,
|
||||
# ../dns.py). First-time order: run this, then `pulumi up`.
|
||||
#
|
||||
# Requires CLOUDFLARE_API_TOKEN + CLOUDFLARE_ACCOUNT_ID (workspace .envrc).
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_NAME="requests-host"
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
: "${CLOUDFLARE_API_TOKEN:?source the workspace .envrc first}"
|
||||
: "${CLOUDFLARE_ACCOUNT_ID:?source the workspace .envrc first}"
|
||||
|
||||
echo "Uploading worker script ${SCRIPT_NAME}..."
|
||||
curl -sS -X PUT "https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/workers/scripts/${SCRIPT_NAME}" \
|
||||
-H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \
|
||||
-F 'metadata={"main_module":"worker.js","compatibility_date":"2026-09-01"};type=application/json' \
|
||||
-F "worker.js=@${HERE}/worker.js;type=application/javascript+module" \
|
||||
| python3 -c "import json,sys; d=json.load(sys.stdin); assert d['success'], d['errors']; print(' uploaded')"
|
||||
|
||||
echo "Smoke test (once the route exists):"
|
||||
echo " curl -sI https://requests.nomadkaraoke.com/ # expect 200, no location header"
|
||||
@@ -0,0 +1 @@
|
||||
{"type":"module"}
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* requests-host: serves the song-request voting board ON requests.nomadkaraoke.com.
|
||||
*
|
||||
* The board is a static page in the gen Pages build (gen.nomadkaraoke.com/en/requests/).
|
||||
* Before this Worker the vanity host 302-redirected there, so the address bar showed the
|
||||
* long gen URL and the short link couldn't be copied back out on mobile (Andrew pastes it
|
||||
* into YouTube comment replies). Now the short URL stays put:
|
||||
*
|
||||
* / -> gen /en/requests/ fetched and returned as-is (query kept)
|
||||
* paths with an extension -> proxied from gen (/_next/* chunks, fonts, icons, sw.js, ...)
|
||||
* any other page path -> 302 to the same path on gen (the app lives there)
|
||||
*
|
||||
* Why a Worker and not a Pages custom domain + URL-rewrite rule: attaching the hostname to
|
||||
* the Pages project made Cloudflare serve it straight from Pages, bypassing the zone's
|
||||
* redirect rules (seen live 2026-10-19), and the Pulumi token can't edit Transform Rules.
|
||||
*
|
||||
* Deploy: ./deploy.sh (script upload). The route requests.nomadkaraoke.com/* is declared
|
||||
* in ../pages_workers.py.
|
||||
*/
|
||||
|
||||
export const GEN_ORIGIN = "https://gen.nomadkaraoke.com"
|
||||
const BOARD_PATH = "/en/requests/"
|
||||
|
||||
export function hasExtension(pathname) {
|
||||
const last = pathname.slice(pathname.lastIndexOf("/") + 1)
|
||||
return last.includes(".")
|
||||
}
|
||||
|
||||
export default {
|
||||
async fetch(request) {
|
||||
const url = new URL(request.url)
|
||||
|
||||
if (url.pathname === "/") {
|
||||
return fetch(new Request(`${GEN_ORIGIN}${BOARD_PATH}${url.search}`, request))
|
||||
}
|
||||
|
||||
if (hasExtension(url.pathname)) {
|
||||
return fetch(new Request(`${GEN_ORIGIN}${url.pathname}${url.search}`, request))
|
||||
}
|
||||
|
||||
return Response.redirect(`${GEN_ORIGIN}${url.pathname}${url.search}`, 302)
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// Run: node --test infrastructure/cloudflare/requests-host/
|
||||
import { test, beforeEach } from "node:test"
|
||||
import assert from "node:assert/strict"
|
||||
import worker, { hasExtension } from "./worker.js"
|
||||
|
||||
let fetched
|
||||
beforeEach(() => {
|
||||
fetched = []
|
||||
globalThis.fetch = async (req) => {
|
||||
fetched.push(req.url)
|
||||
return new Response("upstream", { status: 200, headers: { "content-type": "text/html" } })
|
||||
}
|
||||
})
|
||||
|
||||
test("/ serves the board page from gen, keeping the query string", async () => {
|
||||
const res = await worker.fetch(new Request("https://requests.nomadkaraoke.com/?utm_source=youtube"))
|
||||
assert.equal(res.status, 200)
|
||||
assert.deepEqual(fetched, ["https://gen.nomadkaraoke.com/en/requests/?utm_source=youtube"])
|
||||
})
|
||||
|
||||
test("static assets are proxied from gen", async () => {
|
||||
await worker.fetch(new Request("https://requests.nomadkaraoke.com/_next/static/chunks/abc.js"))
|
||||
await worker.fetch(new Request("https://requests.nomadkaraoke.com/en/requests/index.txt?_rsc=1"))
|
||||
assert.deepEqual(fetched, [
|
||||
"https://gen.nomadkaraoke.com/_next/static/chunks/abc.js",
|
||||
"https://gen.nomadkaraoke.com/en/requests/index.txt?_rsc=1",
|
||||
])
|
||||
})
|
||||
|
||||
test("other page paths redirect to the same path on gen", async () => {
|
||||
const res = await worker.fetch(new Request("https://requests.nomadkaraoke.com/en/app/?x=1"))
|
||||
assert.equal(res.status, 302)
|
||||
assert.equal(res.headers.get("location"), "https://gen.nomadkaraoke.com/en/app/?x=1")
|
||||
assert.deepEqual(fetched, [])
|
||||
})
|
||||
|
||||
test("hasExtension only looks at the last path segment", () => {
|
||||
assert.equal(hasExtension("/favicon.ico"), true)
|
||||
assert.equal(hasExtension("/v1.2/app/"), false)
|
||||
assert.equal(hasExtension("/en/requests"), false)
|
||||
})
|
||||
@@ -170,22 +170,6 @@ ruleset_nomadkaraoke_com_request_dynamic_redirect = cloudflare.Ruleset("ruleset-
|
||||
"expression": "(http.host eq \"pay.nomadkaraoke.com\")",
|
||||
"ref": "763ba6175ef94a2faae1c1840eaf5145",
|
||||
},
|
||||
{
|
||||
"action": "redirect",
|
||||
"action_parameters": {
|
||||
"from_value": {
|
||||
"preserve_query_string": True,
|
||||
"status_code": 302,
|
||||
"target_url": {
|
||||
"value": "https://gen.nomadkaraoke.com/en/requests",
|
||||
},
|
||||
},
|
||||
},
|
||||
"description": "Requests Voting Board Redirect",
|
||||
"enabled": True,
|
||||
"expression": "(http.host eq \"requests.nomadkaraoke.com\")",
|
||||
"ref": "69cb3e389b064f3792d79765a1dc1a41",
|
||||
},
|
||||
],
|
||||
zone_id=ZONE_IDS["nomadkaraoke.com"])
|
||||
ruleset_nomadkaraoke_com_config_settings = cloudflare.Ruleset("ruleset-nomadkaraoke-com-config-settings",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "karaoke-gen"
|
||||
version = "0.278.12"
|
||||
version = "0.278.13"
|
||||
description = "Generate karaoke videos with synchronized lyrics. Handles the entire process from downloading audio and lyrics to creating the final video with title screens."
|
||||
authors = ["Andrew Beveridge <andrew@beveridge.uk>"]
|
||||
license = "MIT"
|
||||
|
||||
Reference in new issue
Block a user