mirror of
https://github.com/djdevin/recflare.git
synced 2026-09-08 06:31:27 -07:00
remove hard coded routes
This commit is contained in:
+6
-11
@@ -6,17 +6,12 @@ Name-server / service-discovery worker served on the `ns` subdomain.
|
||||
discover every service host (Accounts, API, Auth, Econ, Matchmaking,
|
||||
Notifications, …).
|
||||
|
||||
The document is served from `static/endpoints.json`, whose hosts are generated
|
||||
from the repo-root `env.json` by `runx sync` — every entry is derived from the
|
||||
configured base `domain`.
|
||||
Each host is built at runtime from the `DOMAIN` var (the base domain) plus the
|
||||
service → subdomain map in `src/endpoints.ts`. `DOMAIN` is injected at deploy
|
||||
time from the repo-root `env.json` (see `run-wrangler-deploy`) and defaults to
|
||||
`rec.example.com` in `wrangler.jsonc` for local dev.
|
||||
|
||||
## Updating endpoints
|
||||
|
||||
Change `domain` in `env.json` (or edit the host map in `static/endpoints.json`),
|
||||
then regenerate:
|
||||
|
||||
```sh
|
||||
just sync
|
||||
```
|
||||
|
||||
(Bundled at build time, so a redeploy is required for changes to take effect.)
|
||||
- To change the base domain, edit `domain` in `env.json` and redeploy.
|
||||
- To add or rename a service host, edit the map in `src/endpoints.ts`.
|
||||
|
||||
@@ -2,7 +2,12 @@ import type { HonoApp } from '@repo/hono-helpers'
|
||||
import type { SharedHonoEnv, SharedHonoVariables } from '@repo/hono-helpers/src/types'
|
||||
|
||||
export type Env = SharedHonoEnv & {
|
||||
// add additional Bindings here
|
||||
/**
|
||||
* Base domain the service hosts are derived from, e.g. `rec.example.com`.
|
||||
* Injected at deploy time via `--var DOMAIN`; defaults in `wrangler.jsonc`
|
||||
* for local dev and tests.
|
||||
*/
|
||||
DOMAIN: string
|
||||
}
|
||||
|
||||
/** Variables can be extended */
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Service-discovery map: service label → subdomain. The game client fetches the
|
||||
* generated `{ label: "https://<subdomain>.<domain>" }` document from `/`.
|
||||
*
|
||||
* The base domain is injected at deploy time via the `DOMAIN` var (see
|
||||
* `run-wrangler-deploy`), so the real domain never lives in a versioned file.
|
||||
*/
|
||||
const SERVICE_SUBDOMAINS = {
|
||||
Accounts: 'accounts',
|
||||
AI: 'ai',
|
||||
API: 'api',
|
||||
Auth: 'auth',
|
||||
BugReporting: 'bugreporting',
|
||||
Cards: 'cards',
|
||||
CDN: 'cdn',
|
||||
Chat: 'chat',
|
||||
Clubs: 'clubs',
|
||||
CMS: 'cms',
|
||||
Commerce: 'commerce',
|
||||
Data: 'data',
|
||||
DataCollection: 'datacollection',
|
||||
Discovery: 'discovery',
|
||||
Econ: 'econ',
|
||||
GameLogs: 'gamelogs',
|
||||
Geo: 'geo',
|
||||
Images: 'img',
|
||||
Leaderboard: 'leaderboard',
|
||||
Link: 'link',
|
||||
Lists: 'lists',
|
||||
Matchmaking: 'match',
|
||||
Moderation: 'api',
|
||||
Notifications: 'notify',
|
||||
PlatformNotifications: 'platformnotifications',
|
||||
PlayerSettings: 'playersettings',
|
||||
RoomComments: 'roomcomments',
|
||||
RoomieIntegrations: 'roomieintegrations',
|
||||
Rooms: 'rooms',
|
||||
Storage: 'storage',
|
||||
Strings: 'strings',
|
||||
StringsCDN: 'strings-cdn',
|
||||
Studio: 'studio',
|
||||
Thorn: 'thorn',
|
||||
Videos: 'videos',
|
||||
WWW: 'www',
|
||||
} as const
|
||||
|
||||
/** Builds the endpoints document for `domain`, e.g. `rec.example.com`. */
|
||||
export function buildEndpoints(domain: string): Record<string, string> {
|
||||
return Object.fromEntries(
|
||||
Object.entries(SERVICE_SUBDOMAINS).map(([label, sub]) => [label, `https://${sub}.${domain}`])
|
||||
)
|
||||
}
|
||||
@@ -3,15 +3,16 @@ import { useWorkersLogger } from 'workers-tagged-logger'
|
||||
|
||||
import { withNotFound, withOnError } from '@repo/hono-helpers'
|
||||
|
||||
import endpoints from '../static/endpoints.json'
|
||||
import { buildEndpoints } from './endpoints'
|
||||
|
||||
import type { App } from './context'
|
||||
|
||||
/**
|
||||
* Name-server / service-discovery worker served at the apex domain.
|
||||
* Returns the endpoints document the game client fetches to discover every
|
||||
* service host. Generated from `env.json` by `runx sync` — run it after
|
||||
* changing the domain (see `apps/ns/static/endpoints.json`).
|
||||
* service host. Hosts are derived from the `DOMAIN` var, which is injected at
|
||||
* deploy time (see `run-wrangler-deploy`) and defaults in `wrangler.jsonc` for
|
||||
* local dev.
|
||||
*/
|
||||
const app = new Hono<App>()
|
||||
.use(
|
||||
@@ -27,7 +28,7 @@ const app = new Hono<App>()
|
||||
.onError(withOnError())
|
||||
.notFound(withNotFound())
|
||||
|
||||
// Endpoints document. TODO: generate this dynamically per environment.
|
||||
.get('/', (c) => c.json(endpoints))
|
||||
// Endpoints document, derived from the deploy-time base domain.
|
||||
.get('/', (c) => c.json(buildEndpoints(c.env.DOMAIN)))
|
||||
|
||||
export default app
|
||||
|
||||
@@ -2,16 +2,19 @@ import { exports } from 'cloudflare:workers'
|
||||
import { describe, expect, test } from 'vitest'
|
||||
|
||||
import '../../ns.app'
|
||||
import endpoints from '../../../static/endpoints.json'
|
||||
import { buildEndpoints } from '../../endpoints'
|
||||
|
||||
const ORIGIN = 'https://example.com'
|
||||
|
||||
// Must match the DOMAIN var default in apps/ns/wrangler.jsonc.
|
||||
const TEST_DOMAIN = 'rec.example.com'
|
||||
|
||||
describe('ns endpoints', () => {
|
||||
test('GET / returns the endpoints document', async () => {
|
||||
const res = await exports.default.fetch(`${ORIGIN}/`)
|
||||
expect(res.status).toBe(200)
|
||||
const body = await res.json()
|
||||
expect(body).toEqual(endpoints)
|
||||
expect(body).toEqual(buildEndpoints(TEST_DOMAIN))
|
||||
})
|
||||
|
||||
test('unknown path returns 404', async () => {
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
{
|
||||
"Accounts": "https://accounts.rec.example.com",
|
||||
"AI": "https://ai.rec.example.com",
|
||||
"API": "https://api.rec.example.com",
|
||||
"Auth": "https://auth.rec.example.com",
|
||||
"BugReporting": "https://bugreporting.rec.example.com",
|
||||
"Cards": "https://cards.rec.example.com",
|
||||
"CDN": "https://cdn.rec.example.com",
|
||||
"Chat": "https://chat.rec.example.com",
|
||||
"Clubs": "https://clubs.rec.example.com",
|
||||
"CMS": "https://cms.rec.example.com",
|
||||
"Commerce": "https://commerce.rec.example.com",
|
||||
"Data": "https://data.rec.example.com",
|
||||
"DataCollection": "https://datacollection.rec.example.com",
|
||||
"Discovery": "https://discovery.rec.example.com",
|
||||
"Econ": "https://econ.rec.example.com",
|
||||
"GameLogs": "https://gamelogs.rec.example.com",
|
||||
"Geo": "https://geo.rec.example.com",
|
||||
"Images": "https://img.rec.example.com",
|
||||
"Leaderboard": "https://leaderboard.rec.example.com",
|
||||
"Link": "https://link.rec.example.com",
|
||||
"Lists": "https://lists.rec.example.com",
|
||||
"Matchmaking": "https://match.rec.example.com",
|
||||
"Moderation": "https://api.rec.example.com",
|
||||
"Notifications": "https://notify.rec.example.com",
|
||||
"PlatformNotifications": "https://platformnotifications.rec.example.com",
|
||||
"PlayerSettings": "https://playersettings.rec.example.com",
|
||||
"RoomComments": "https://roomcomments.rec.example.com",
|
||||
"RoomieIntegrations": "https://roomieintegrations.rec.example.com",
|
||||
"Rooms": "https://rooms.rec.example.com",
|
||||
"Storage": "https://storage.rec.example.com",
|
||||
"Strings": "https://strings.rec.example.com",
|
||||
"StringsCDN": "https://strings-cdn.rec.example.com",
|
||||
"Studio": "https://studio.rec.example.com",
|
||||
"Thorn": "https://thorn.rec.example.com",
|
||||
"Videos": "https://videos.rec.example.com",
|
||||
"WWW": "https://www.rec.example.com"
|
||||
}
|
||||
@@ -4,12 +4,6 @@
|
||||
"main": "src/ns.app.ts",
|
||||
"compatibility_date": "2025-09-20",
|
||||
"compatibility_flags": ["nodejs_compat"],
|
||||
"routes": [
|
||||
{
|
||||
"pattern": "ns.rec.example.com",
|
||||
"custom_domain": true
|
||||
}
|
||||
],
|
||||
"logpush": false,
|
||||
"upload_source_maps": true,
|
||||
"observability": {
|
||||
@@ -20,6 +14,7 @@
|
||||
},
|
||||
"vars": {
|
||||
"ENVIRONMENT": "development", // overridden during deployment
|
||||
"SENTRY_RELEASE": "unknown" // overridden during deployment
|
||||
"SENTRY_RELEASE": "unknown", // overridden during deployment
|
||||
"DOMAIN": "rec.example.com" // base domain; overridden during deployment
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user