mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 10:02:59 +08:00
feat(server): remove the use of "any" for metrics endpoint
This commit is contained in:
parent
52fb5fa298
commit
758b22e6b1
@ -1,4 +1,4 @@
|
||||
import type { Router } from "express";
|
||||
import type { Router, Request, Response, NextFunction } from "express";
|
||||
import eu from "./etapi_utils.js";
|
||||
import sql from "../services/sql.js";
|
||||
import appInfo from "../services/app_info.js";
|
||||
@ -238,8 +238,8 @@ function collectMetrics(): MetricsData {
|
||||
};
|
||||
}
|
||||
|
||||
function register(router: Router) {
|
||||
eu.route(router, "get", "/etapi/metrics", (req, res, next) => {
|
||||
function register(router: Router): void {
|
||||
eu.route(router, "get", "/etapi/metrics", (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
const metrics = collectMetrics();
|
||||
const format = (req.query.format as string)?.toLowerCase() || 'prometheus';
|
||||
@ -254,8 +254,9 @@ function register(router: Router) {
|
||||
} else {
|
||||
throw new eu.EtapiError(400, "INVALID_FORMAT", "Supported formats: 'prometheus' (default), 'json'");
|
||||
}
|
||||
} catch (error: any) {
|
||||
throw new eu.EtapiError(500, "METRICS_ERROR", `Failed to collect metrics: ${error.message}`);
|
||||
} catch (error: unknown) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
||||
throw new eu.EtapiError(500, "METRICS_ERROR", `Failed to collect metrics: ${errorMessage}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
import type { Request, Response } from "express";
|
||||
import etapiMetrics from "../../etapi/metrics.js";
|
||||
|
||||
type MetricsData = ReturnType<typeof etapiMetrics.collectMetrics>;
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /api/metrics:
|
||||
@ -148,7 +151,7 @@ import etapiMetrics from "../../etapi/metrics.js";
|
||||
* security:
|
||||
* - session: []
|
||||
*/
|
||||
function getMetrics(req: any, res: any): any {
|
||||
function getMetrics(req: Request, res: Response): string | MetricsData {
|
||||
const format = (req.query?.format as string)?.toLowerCase() || 'prometheus';
|
||||
|
||||
if (format === 'json') {
|
||||
|
Loading…
x
Reference in New Issue
Block a user