#523

Feature request: a hook for the proxy's own pages (404, 502, 508)

Opengstanglopened 16d ago

Feature request: a hook for the proxy's own pages (404, 502, 508)

Our team runs every local app and preview through portless. When an address has no app, the dev server is down or a request loops, the proxy answers with its own page. Those pages are the first thing people see when something goes wrong locally. We'd like them to match the rest of our tooling: same language, same look, and our own next step, such as the exact restart command for our setup.

Today the only way to do that is to patch renderPage in the installed bundle, which is what we do now. It works, but the patch breaks on every release.

Proposal

An optional render hook, configured the same way as other proxy options (for example PORTLESS_ERROR_PAGE=/path/to/module.mjs, or an errorPage option in createProxyServer). portless calls it with structured context instead of pre-rendered HTML:

// module.mjs
export default function render({ status, host, path, routes, code, hops }) {
  return '<!doctype html>…' // or null to keep the built-in page
}
  • status: 404, 502 or 508
  • host / path: what was requested
  • routes: registered hostnames (404)
  • code: the socket error code, e.g. ECONNREFUSED (502)
  • hops: the loop count (508)

If the module is missing, throws or returns null, the built-in page renders as today. This would also give #254's content negotiation a natural home: the hook could receive the request's Accept header.

We're happy to send a PR if this direction works for you.

Activity

0

No activity yet.