Skip to content

Commit a42a813

Browse files
author
hirsch88
committed
Add custom config
1 parent dc55d6e commit a42a813

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "A delightful way to building a RESTful API with NodeJs & TypeScript",
55
"main": "src/app.ts",
66
"engines": {
7-
"node": "7.7.3"
7+
"node": "8.2.1"
88
},
99
"scripts": {
1010
"start": "node dist/app.js",
@@ -63,6 +63,7 @@
6363
"@types/request": "^2.0.7",
6464
"@types/request-promise": "^4.1.39",
6565
"@types/serve-favicon": "^2.2.29",
66+
"@types/uuid": "^3.4.3",
6667
"@types/winston": "^2.3.7",
6768
"body-parser": "^1.18.2",
6869
"bookshelf": "^0.10.4",
@@ -103,6 +104,7 @@
103104
"ts-node": "^3.3.0",
104105
"tslint": "^5.8.0",
105106
"typescript": "^2.6.1",
107+
"uuid": "^3.1.0",
106108
"wait-on": "^2.0.2",
107109
"winston": "^2.4.0"
108110
},

src/config/CustomConfig.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
* Define all log adapters for this application and chose one.
66
*/
77

8+
import * as express from 'express';
9+
import * as uuid from 'uuid';
10+
811
import { Logger } from '../core/Logger';
912
import { App, Configurable } from '../core/App';
13+
import { Environment } from '../core/helpers/Environment';
1014

1115

1216
export class CustomConfig implements Configurable {
@@ -15,6 +19,13 @@ export class CustomConfig implements Configurable {
1519

1620
public configure(app: App): void {
1721
this.log.debug('configuring', app.Express.get('port'));
22+
23+
app.Express.use((req: express.Request, res: express.Response, next: express.NextFunction) => {
24+
res.setHeader('X-API-VERSION', Environment.getPkg().version);
25+
res.setHeader('X-Request-Id', uuid.v4());
26+
next();
27+
});
28+
1829
}
1930
}
2031

src/core/ApiInfo.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as express from 'express';
22
import { Environment } from './helpers/Environment';
33
import { SwaggerUI } from './SwaggerUI';
44
import { ApiMonitor } from './ApiMonitor';
5-
import { BasicAuthenticate } from './BasicAuthenticate';
5+
// import { BasicAuthenticate } from './BasicAuthenticate';
66

77

88
export class ApiInfo {
@@ -16,8 +16,6 @@ export class ApiInfo {
1616
application.get(
1717
ApiInfo.getRoute(),
1818
// @ts-ignore: False type definitions from express
19-
BasicAuthenticate(),
20-
// @ts-ignore: False type definitions from express
2119
(req: myExpress.Request, res: myExpress.Response) => {
2220
const pkg = Environment.getPkg();
2321
const links = {

yarn.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@
270270
dependencies:
271271
"@types/node" "*"
272272

273+
"@types/uuid@^3.4.3":
274+
version "3.4.3"
275+
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-3.4.3.tgz#121ace265f5569ce40f4f6d0ff78a338c732a754"
276+
dependencies:
277+
"@types/node" "*"
278+
273279
"@types/winston@^2.3.7":
274280
version "2.3.7"
275281
resolved "https://registry.yarnpkg.com/@types/winston/-/winston-2.3.7.tgz#2ea18b2dc772d459b6af0f587447704df31afec2"

0 commit comments

Comments
 (0)