Expose a small backend identity/version descriptor (§8.4 of the Android plan)
so a client can positively recognize a Runic Gateway backend on first-run and
run a version-mismatch guard, instead of inferring from an incidental shape.
- New config/version.js: { service: 'runic-gateway', api: 'v1', server: <pkg> }.
- GET /public/status now includes a `version` block (the app already calls this
on first-run, so it gets identity + version in one round trip).
- New GET /public/version: a lightweight, DB-free identity endpoint — the
canonical target for the version guard and a cheap liveness check.
- Swagger: PublicVersion schema + version on PublicStatus; /version annotated.
- test/publicVersion.test.js covers the config shape and the DB-free 200.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NgyHnrNa8WwG3doxvxjuCr
37 lines
1.4 KiB
JavaScript
37 lines
1.4 KiB
JavaScript
// Point the DB at a closed port BEFORE requiring the router (some public handlers
|
|
// build the pool). The /version endpoint itself is DB-free, so it answers without
|
|
// a connection; this just guarantees no stray query holds the process open.
|
|
process.env.DB_HOST = '127.0.0.1'
|
|
process.env.DB_PORT = '59999'
|
|
|
|
const { test, after } = require('node:test')
|
|
const assert = require('node:assert/strict')
|
|
|
|
const { startApp } = require('./_helper')
|
|
const version = require('../src/config/version')
|
|
const publicRouter = require('../src/router/v1/public/public.routes')
|
|
const db = require('../src/utils/db')
|
|
|
|
after(() => db.close())
|
|
|
|
test('version config carries the service id + api/server versions', () => {
|
|
assert.equal(version.service, 'runic-gateway') // stable first-run identifier
|
|
assert.equal(version.api, 'v1') // API contract version (matches /api/v1)
|
|
assert.equal(typeof version.server, 'string')
|
|
assert.ok(version.server.length > 0)
|
|
})
|
|
|
|
test('GET /public/version returns the identity block (DB-free, 200)', async () => {
|
|
const app = await startApp((a) => a.use('/api/v1/public', publicRouter))
|
|
try {
|
|
const res = await fetch(app.url + '/api/v1/public/version')
|
|
assert.equal(res.status, 200)
|
|
const body = await res.json()
|
|
assert.equal(body.service, 'runic-gateway')
|
|
assert.equal(body.api, 'v1')
|
|
assert.equal(body.server, version.server)
|
|
} finally {
|
|
await app.close()
|
|
}
|
|
})
|