@villedemontreal/correlation-id
Version:
Express middleware to set a correlation in Express. The correlation id will be consistent across async calls within the handling of a request.
41 lines (35 loc) • 958 B
text/typescript
import { path as appRoot } from 'app-root-path';
import * as path from 'path';
/**
* Library constants
*/
export class Constants {
/**
* The library root. When this library is used
* as a dependency in a project, the "libRoot"
* will be the path to the dependency folder,
* inside the "node_modules".
*/
public libRoot: string;
/**
* The app root. When this library is used
* as a dependency in a project, the "appRoot"
* will be the path to the root project!
*/
public appRoot: string;
constructor() {
// From the "dist/src/config" folder
this.libRoot = path.normalize(path.join(__dirname, '/../../..'));
this.appRoot = appRoot;
}
/**
* Extra values that we can add to the original Express request.
*/
get requestExtraVariables() {
return {
cidReceivedInRequest: '_cidReceivedInRequest',
cidNew: '_cidNew',
};
}
}
export const constants: Constants = new Constants();