Added middlewares for authKey and detailed request
logging
This commit is contained in:
parent
8b0969792a
commit
f56fae304e
14
src/api/middlewares/authKey.js
Normal file
14
src/api/middlewares/authKey.js
Normal 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();
|
||||
};
|
||||
10
src/api/middlewares/detailedRequestLogging.js
Normal file
10
src/api/middlewares/detailedRequestLogging.js
Normal 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();
|
||||
};
|
||||
9
src/api/middlewares/index.js
Normal file
9
src/api/middlewares/index.js
Normal 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);
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user