Skip to content

Commit

Permalink
Prometheus password fix (#1319)
Browse files Browse the repository at this point in the history
* Russian translation

* Fix require prometheus password

---------

Co-authored-by: Vadim Babadzhanyan <[email protected]>
  • Loading branch information
AKEB and Vadim Babadzhanyan authored Sep 10, 2024
1 parent e2fe3b8 commit 6e891ad
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,22 +336,17 @@ module.exports = class Server {
});
};

// Prometheus Metrics API
const routerPrometheusMetrics = createRouter();
app.use(routerPrometheusMetrics);

// Check Prometheus credentials
app.use(
fromNodeMiddleware((req, res, next) => {
if (!requiresPrometheusPassword || !req.url.startsWith('/metrics')) {
return next();
}
const user = basicAuth(req);
if (requiresPrometheusPassword && !user) {
if (!user) {
res.statusCode = 401;
return { error: 'Not Logged In' };
}

if (user.pass) {
if (isPasswordValid(user.pass, PROMETHEUS_METRICS_PASSWORD)) {
return next();
Expand All @@ -364,6 +359,10 @@ module.exports = class Server {
}),
);

// Prometheus Metrics API
const routerPrometheusMetrics = createRouter();
app.use(routerPrometheusMetrics);

// Prometheus Routes
routerPrometheusMetrics
.get('/metrics', defineEventHandler(async (event) => {
Expand Down

0 comments on commit 6e891ad

Please sign in to comment.