mirror of
https://github.com/djdevin/recflare.git
synced 2026-09-09 07:01:27 -07:00
use path prefixes to make it easy
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { exports } from 'cloudflare:workers'
|
||||
import { describe, expect, test } from 'vitest'
|
||||
|
||||
import type { Env } from '../../context'
|
||||
|
||||
declare module 'cloudflare:test' {
|
||||
interface ProvidedEnv extends Env {}
|
||||
}
|
||||
|
||||
const ORIGIN = 'https://example.com'
|
||||
|
||||
// The facade's job is routing, not business logic, so one request that reaches a
|
||||
// mounted app through the path prefix is enough to prove the wiring. `api` serves a
|
||||
// static game-config with no auth/DB, so it's a clean target. The api worker namespaces
|
||||
// its own routes under `/api`, hence the `/api` prefix (service) + `/api/...` (real path).
|
||||
describe('mono routing', () => {
|
||||
test('path prefix routes to the api worker (gameconfigs)', async () => {
|
||||
const res = await exports.default.fetch(`${ORIGIN}/api/api/gameconfigs/v1/all`)
|
||||
expect(res.status).toBe(200)
|
||||
// Reached the api app's real handler, not the facade's 404.
|
||||
expect(res.headers.get('content-type')).toContain('application/json')
|
||||
})
|
||||
|
||||
test('unknown service prefix returns the facade 404', async () => {
|
||||
const res = await exports.default.fetch(`${ORIGIN}/nope/whatever`)
|
||||
expect(res.status).toBe(404)
|
||||
expect(await res.json()).toMatchObject({ error: 'unknown_service' })
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user