Repository navigation
proxy-1.13.0
Requires pg-boss 12.38.0 or later.
- The proxy registers in the instance registry as
pg-boss-proxy, or under the name you give it. - New environment variable
PGBOSS_PROXY_INSTANCE_NAME. - New option
authorize, called for each API request with the pg-boss method it calls. - Several proxy services can be mounted in one Hono app, each with its own pages and docs.
Highlights
Named in the instance list
Through 1.12.0 the proxy's pg-boss instance showed in getInstances() with no name, next to your
own workers. It now registers as pg-boss-proxy unless you name it:
instanceNamein the constructor options passed tocreateProxyService()PGBOSS_PROXY_INSTANCE_NAMEpg-boss-proxy
DATABASE_URL=postgres://user:pass@host/database \
PGBOSS_PROXY_INSTANCE_NAME=edge-proxy \
npx pg-boss-proxy
Naming each deployment is useful when several proxies share a database, or when one runs with
supervise, schedule or migrate turned on.
Authorizing each call
middleware runs before every API route without knowing which method was called, and
routes.allow/deny is fixed when the service starts. authorize decides each request with the
method name, so access can depend on who is calling:
const { app } = await createProxyService({
options: { connectionString },
middleware: [identifyCaller],
authorize: (context, method) => context.get('caller')?.methods.includes(method) ?? false
})It runs after middleware and before the request is validated. true lets the call through, false
refuses it with a 403, and { status, message } refuses it with that status, keeping any header the
hook set, such as WWW-Authenticate. Anything else refuses the call. /meta is authorized as
meta. The pages are not passed to it.
Mounting several services
A service's app mounted with parent.route('/db/a', app) now links its root page, docs and spec
through the mount, and the spec lists the mount as its server, so the docs' Try it out calls that
mount. Before, they linked to /docs and /openapi.json at the root of the parent. With one service
per database and prefix: '', one app serves several databases at /db/<name>/send.
Upgrading
No changes needed. A proxy that already passes instanceName keeps it.
Fixes
- With
prefix: ''(or/), the root page linked to//metaand listed methods as//send, which
a browser reads as another host. They are/metaand/sendnow.
Notes
- Dependency updates.
- Version: a minor (1.13.0), for the new
authorizeoption.