Skip to content

proxy-1.13.0

Choose a tag to compare

@timgit timgit released this 15 Oct 18:39
· 2 commits to master since this release
d440085

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:

  1. instanceName in the constructor options passed to createProxyService()
  2. PGBOSS_PROXY_INSTANCE_NAME
  3. pg-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 //meta and listed methods as //send, which
    a browser reads as another host. They are /meta and /send now.

Notes

  • Dependency updates.
  • Version: a minor (1.13.0), for the new authorize option.