jsm-core
Version:
Core library for JSM project
43 lines (42 loc) • 1.56 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const morgan_1 = __importDefault(require("morgan"));
const context_1 = require("../../context");
exports.default = ({ app }) => {
// app.use(morgan(
// ':method :url :status :res[content-length] - :response-time ms',
// {
// stream: {
// // Configure Morgan to use our custom logger with the http severity
// write: (message) => LoggerInstance.http(message.trim()),
// },
// }
// ));
app.use((req, res, next) => {
var _a;
const httpRequest = {
method: req.method,
path: req.path,
service: (_a = (0, context_1.getRegistry)().getConfig('currentService.name')) === null || _a === void 0 ? void 0 : _a.toLowerCase(),
query: req.query,
body: req.body,
ip: req.ip,
headers: req.headers
};
next();
if (httpRequest.service !== "log" && httpRequest.service !== "gateway") {
// log(req as any, {
// service: httpRequest.service,
// name: "HTTP",
// type: "http",
// severity: "info",
// payload: httpRequest,
// }, config.levelup.log)
// console.log(colors.magenta("REQUEST"), httpRequest);
}
});
app.use((0, morgan_1.default)('dev'));
};