Added middlewares for authKey and detailed request

logging
This commit is contained in:
Peter Morton 2023-07-26 16:56:38 -05:00
parent 8b0969792a
commit f56fae304e
3 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,14 @@
import localStorage from "local-storage";
import createHttpError from "http-errors";
export default (req, res, next) => {
if (localStorage(req.query.authKey) == null) {
next(
new createHttpError.Forbidden(
`middleware:authKey ${req.query.authKey} not authenticated`
)
);
return;
}
next();
};

View File

@ -0,0 +1,10 @@
import { logger } from "../../utils/index.js";
export default (req, res, next) => {
logger.debug(`URI: ${req.method} ${req.protocol}://${req.hostname}:${req.client.localPort}${req.originalUrl}`);
logger.debug(`Headers: ${JSON.stringify(req.headers, null, 2)}`);
logger.debug(`Cookies: ${JSON.stringify(req.cookies, null, 2)}`);
logger.debug(`Query: ${JSON.stringify(req.query, null, 2)}`);
logger.debug(`Body: ${JSON.stringify(req.body, null, 2)}`);
next();
};

View File

@ -0,0 +1,9 @@
// import { Router } from "express";
import authKey from "./authKey.js";
import detailedRequestLogging from "./detailedRequestLogging.js";
export default (router) => {
router.use("/", detailedRequestLogging);
router.use("/interactions-flow", authKey);
router.use("/unified-data-gateway", authKey);
};