diff --git a/changelog.d/435.bugfix b/changelog.d/435.bugfix new file mode 100644 index 00000000..f9ea83ba --- /dev/null +++ b/changelog.d/435.bugfix @@ -0,0 +1 @@ +Fix bug introduced in 5.0.0 which caused the `/metrics` endpoint to request authentication. The endpoint no longer requires authentication. \ No newline at end of file diff --git a/src/bridge.ts b/src/bridge.ts index cbdc26b2..1e349fd2 100644 --- a/src/bridge.ts +++ b/src/bridge.ts @@ -958,24 +958,25 @@ export class Bridge { * Install a custom handler for an incoming HTTP API request. This allows * callers to add extra functionality, implement new APIs, etc... * @param opts Named options + * @param opts.authenticate Should the token be automatically checked. Defaults to true. + * @param opts.handler Function to handle requests * @param opts.method The HTTP method name. * @param opts.path Path to the endpoint. - * @param opts.checkToken Should the token be automatically checked. Defaults to true. - * @param opts.handler Function to handle requests * to this endpoint. */ public addAppServicePath(opts: { method: "GET"|"PUT"|"POST"|"DELETE", path: string, + authenticate?: boolean, handler: (req: ExRequest, respose: ExResponse, next: NextFunction) => void, }): void { if (!this.appservice) { throw Error('Cannot call addAppServicePath before calling .run()'); } const app: Application = this.appservice.expressApp; - + const authenticate = opts.authenticate ?? true; app[opts.method.toLowerCase() as "get"|"put"|"post"|"delete"](opts.path, (req, res, ...args) => { - if (!this.requestCheckToken(req)) { + if (authenticate && !this.requestCheckToken(req)) { return res.status(403).send({ errcode: "M_FORBIDDEN", error: "Bad token supplied," diff --git a/src/components/prometheusmetrics.ts b/src/components/prometheusmetrics.ts index 6e411359..92c25ec4 100644 --- a/src/components/prometheusmetrics.ts +++ b/src/components/prometheusmetrics.ts @@ -398,6 +398,7 @@ export class PrometheusMetrics { public addAppServicePath(bridge: Bridge): void { bridge.addAppServicePath({ method: "GET", + authenticate: false, path: "/metrics", handler: async (_req: Request, res: Response) => { try {