|
|
@ -138,34 +138,27 @@ export const defineMetricsHandler = < |
|
|
|
handler: MetricsHandler<TReq, TRes> |
|
|
|
) => { |
|
|
|
return defineEventHandler(async (event) => { |
|
|
|
const auth = getHeader(event, 'Authorization'); |
|
|
|
|
|
|
|
if (!auth) { |
|
|
|
throw createError({ |
|
|
|
statusCode: 401, |
|
|
|
statusMessage: 'Unauthorized', |
|
|
|
}); |
|
|
|
} |
|
|
|
const metricsConfig = await Database.general.getMetricsConfig(); |
|
|
|
|
|
|
|
const [method, value] = auth.split(' '); |
|
|
|
if (metricsConfig.password) { |
|
|
|
const auth = getHeader(event, 'Authorization'); |
|
|
|
|
|
|
|
if (method !== 'Bearer' || !value) { |
|
|
|
throw createError({ |
|
|
|
statusCode: 401, |
|
|
|
statusMessage: 'Bearer Auth required', |
|
|
|
}); |
|
|
|
} |
|
|
|
if (!auth) { |
|
|
|
throw createError({ |
|
|
|
statusCode: 401, |
|
|
|
statusMessage: 'Unauthorized', |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
const metricsConfig = await Database.general.getMetricsConfig(); |
|
|
|
const [method, value] = auth.split(' '); |
|
|
|
|
|
|
|
if (metricsConfig[type] !== true) { |
|
|
|
throw createError({ |
|
|
|
statusCode: 400, |
|
|
|
statusMessage: 'Metrics not enabled', |
|
|
|
}); |
|
|
|
} |
|
|
|
if (method !== 'Bearer' || !value) { |
|
|
|
throw createError({ |
|
|
|
statusCode: 401, |
|
|
|
statusMessage: 'Bearer Auth required', |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
if (metricsConfig.password) { |
|
|
|
const tokenValid = await isPasswordValid(value, metricsConfig.password); |
|
|
|
|
|
|
|
if (!tokenValid) { |
|
|
@ -176,6 +169,13 @@ export const defineMetricsHandler = < |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (metricsConfig[type] !== true) { |
|
|
|
throw createError({ |
|
|
|
statusCode: 400, |
|
|
|
statusMessage: 'Metrics not enabled', |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
return await handler({ event }); |
|
|
|
}); |
|
|
|
}; |
|
|
|