tweak for returning ns

This commit is contained in:
Devin Zuczek
2026-07-20 18:15:20 -04:00
parent aebd4ca630
commit 9ab4199bd5
3 changed files with 14 additions and 1 deletions
-1
View File
@@ -9,7 +9,6 @@
"check:lint": "run-oxlint",
"check:types": "run-tsc",
"check:workers-types": "run-wrangler-types --check",
"deploy": "run-wrangler-deploy",
"dev": "run-wrangler-dev",
"fix:workers-types": "run-wrangler-types",
"test": "run-vitest"
+7
View File
@@ -13,6 +13,9 @@
* http://localhost:8787/match/player/login -> match app sees /player/login
* http://localhost:8787/api/api/config/v2 -> api app sees /api/config/v2
*
* A bare hit to the facade's own host (mono.<domain>) has no service subdomain and no
* prefix, so it falls back to the `ns` discovery worker — clients bootstrap from there.
*
* NOT mounted here: `www`, `img`, `econ`. Each binds a static `assets` directory and
* Cloudflare allows only one static-assets binding per Worker. Resolve that (serve
* their static trees from R2, or keep those three as their own Workers) before adding.
@@ -80,6 +83,10 @@ function resolve(request: Request): { name: ServiceName; request: Request } | un
return { name: first as ServiceName, request: new Request(url, request) }
}
// The facade's own host (mono.<domain>) carries no service subdomain. Fall back to
// the `ns` discovery worker so a bare hit returns the service map, like the apex/ns host.
if (sub === 'mono') return { name: 'ns', request }
return undefined
}
@@ -21,6 +21,13 @@ describe('mono routing', () => {
expect(res.headers.get('content-type')).toContain('application/json')
})
test('the facade host (mono.<domain>) falls back to the ns discovery worker', async () => {
const res = await exports.default.fetch('https://mono.recflare.net/')
expect(res.status).toBe(200)
// The ns worker serves the service-discovery document.
expect(await res.json()).toHaveProperty('Auth')
})
test('unknown service prefix returns the facade 404', async () => {
const res = await exports.default.fetch(`${ORIGIN}/nope/whatever`)
expect(res.status).toBe(404)