[CORL-281] Metrics (#2298)

* feat: iunitial metrics implementation

* fix: graphql endpoint was throwing errors.

* feat: add metrics env variables to readme
This commit is contained in:
Wyatt Johnson
2019-05-10 00:26:24 +02:00
committed by Kiwi
parent df57b4eb17
commit d4b8e5ef70
21 changed files with 461 additions and 92 deletions
@@ -0,0 +1,32 @@
import auth from "basic-auth";
import compare from "tsscmp";
import { RequestHandler } from "talk-server/types/express";
export const basicAuth = (
username: string,
password: string
): RequestHandler => {
function check(name: string, pass: string) {
let valid = true;
// Simple method to prevent short-circuit and use timing-safe compare.
valid = compare(name, username) && valid;
valid = compare(pass, password) && valid;
return valid;
}
return (req, res, next) => {
// Pull the credentials out of the request.
const credentials = auth(req);
// Check credentials
if (credentials && check(credentials.name, credentials.pass)) {
return next();
}
res.setHeader("WWW-Authenticate", `Basic realm="${req.originalUrl}"`);
res.status(401).send("Access denied");
};
};