MCPcopy Create free account
hub / github.com/evolution-foundation/evolution-api / metricsBasicAuth

Function metricsBasicAuth

src/api/routes/index.router.ts:66–89  ·  view source on GitHub ↗
(req: Request, res: Response, next: NextFunction)

Source from the content-addressed store, hash-verified

64
65// Middleware for metrics Basic Authentication
66const metricsBasicAuth = (req: Request, res: Response, next: NextFunction) => {
67 const metricsConfig = configService.get('METRICS');
68 const metricsUser = metricsConfig.USER;
69 const metricsPass = metricsConfig.PASSWORD;
70
71 if (!metricsUser || !metricsPass) {
72 return res.status(500).send('Metrics authentication not configured');
73 }
74
75 const auth = req.get('Authorization');
76 if (!auth || !auth.startsWith('Basic ')) {
77 res.set('WWW-Authenticate', 'Basic realm="Evolution API Metrics"');
78 return res.status(401).send('Authentication required');
79 }
80
81 const credentials = Buffer.from(auth.slice(6), 'base64').toString();
82 const [user, pass] = credentials.split(':');
83
84 if (user !== metricsUser || pass !== metricsPass) {
85 return res.status(401).send('Invalid credentials');
86 }
87
88 next();
89};
90
91// Expose Prometheus metrics when enabled by env flag
92const metricsConfig = configService.get('METRICS');

Callers

nothing calls this directly

Calls 4

statusMethod · 0.80
toStringMethod · 0.80
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected