nginx-proxy-manager/backend/lib/upstream/errors.js
Tom Winnerl 6bd369299a feat(upstreams): discovery, reachability check and health monitor
New /api/upstreams endpoints that help picking and watching forward hosts:

- GET /upstreams/candidates suggests upstreams from three sources: hosts
  already used by other proxy hosts/streams, containers found through
  Docker's embedded DNS on the networks NPM is attached to
  (NPM_DNS_DISCOVERY, on by default) and, opt-in, containers from the
  Docker API (NPM_DOCKER_DISCOVERY + DOCKER_HOST, e.g. a docker-socket-proxy).
- POST /upstreams/check resolves a host with the same resolver nginx uses
  and opens a TCP connection to the port, returning a status code
  (ok, dns_not_found, tcp_refused, ...) and the round trip time. Checks
  are rate limited per user and can be turned off with NPM_UPSTREAM_CHECK=false.
- GET /upstreams/health returns the results of a background monitor that
  checks the targets of all enabled hosts every NPM_UPSTREAM_HEALTH_INTERVAL
  seconds (default 60, 0 turns it off). It shows the hosts the proxy host
  and stream lists show the user (with proxy hosts shared through
  permissions.meta.proxy_host_ids). The monitor starts with the backend
  and stops on SIGTERM.

Access is controlled by the new upstreams:discover permission (users who may
manage proxy hosts or streams); access.can() gets a quiet option so this
lookup doesn't log a denial for every request. The OpenAPI schema
documents the three paths and their result objects.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 09:03:56 +01:00

19 lines
662 B
JavaScript

/**
* Errors specific to the upstream endpoints. They follow the shape of lib/error.js
* (public + status) so the app error handler renders them like every other public error.
*/
function TooManyRequestsError(message, retryAfter, previous) {
Error.captureStackTrace(this, TooManyRequestsError);
this.name = "TooManyRequestsError";
this.previous = previous;
this.message = message || "Too many requests";
this.retry_after = retryAfter || null;
this.public = true;
this.status = 429;
}
TooManyRequestsError.prototype = Object.create(Error.prototype);
TooManyRequestsError.prototype.constructor = TooManyRequestsError;
export { TooManyRequestsError };