@nimee/initialize-ms 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/fastify.d.ts +5 -0
- package/dist/src/fastify.js +17 -1
- package/dist/src/fastify.js.map +1 -1
- package/package.json +9 -7
- package/src/fastify.ts +25 -2
- package/nodemon.json +0 -6
package/dist/src/fastify.d.ts
CHANGED
package/dist/src/fastify.js
CHANGED
|
@@ -14,15 +14,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const fastify_1 = __importDefault(require("fastify"));
|
|
16
16
|
const logger_1 = __importDefault(require("@nimee/logger"));
|
|
17
|
+
const request_context_1 = __importDefault(require("@fastify/request-context"));
|
|
18
|
+
const uuid_1 = require("uuid");
|
|
17
19
|
class ServerInitializerFastify {
|
|
18
20
|
initialize(serviceName) {
|
|
19
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
22
|
try {
|
|
21
|
-
this.server = (0, fastify_1.default)({
|
|
23
|
+
this.server = (0, fastify_1.default)({
|
|
24
|
+
logger: logger_1.default,
|
|
25
|
+
requestIdLogLabel: "reqId",
|
|
26
|
+
genReqId(req) {
|
|
27
|
+
// you get access to the req here if you need it - must be a synchronous function
|
|
28
|
+
return (0, uuid_1.v4)();
|
|
29
|
+
},
|
|
30
|
+
});
|
|
22
31
|
this.server.register(require("@fastify/cors"), {
|
|
23
32
|
origin: ["http://localhost:8080", "http://127.0.0.1:8080", "http://localhost:3000"],
|
|
24
33
|
methods: ["GET", "PUT", "PATCH", "POST", "DELETE"],
|
|
25
34
|
});
|
|
35
|
+
this.server.register(request_context_1.default, {
|
|
36
|
+
hook: "preValidation",
|
|
37
|
+
});
|
|
38
|
+
// this.server.addHook("preHandler", async (request: any) => {
|
|
39
|
+
// requestContext.set("user", request.user);
|
|
40
|
+
// logger.info(`1user:${requestContext.get("user")}`);
|
|
41
|
+
// });
|
|
26
42
|
return this.server;
|
|
27
43
|
}
|
|
28
44
|
catch (err) {
|
package/dist/src/fastify.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastify.js","sourceRoot":"","sources":["../../src/fastify.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"fastify.js","sourceRoot":"","sources":["../../src/fastify.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sDAAkD;AAClD,2DAAmC;AACnC,+EAAmE;AACnE,+BAAkC;AAQlC,MAAM,wBAAwB;IAEtB,UAAU,CAAC,WAAoB;;YACnC,IAAI;gBACF,IAAI,CAAC,MAAM,GAAG,IAAA,iBAAO,EAAC;oBACpB,MAAM,EAAN,gBAAM;oBACN,iBAAiB,EAAE,OAAO;oBAC1B,QAAQ,CAAC,GAAmB;wBAC1B,iFAAiF;wBACjF,OAAO,IAAA,SAAI,GAAE,CAAC;oBAChB,CAAC;iBACF,CAAC,CAAC;gBAEH,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE;oBAC7C,MAAM,EAAE,CAAC,uBAAuB,EAAE,uBAAuB,EAAE,uBAAuB,CAAC;oBACnF,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC;iBACnD,CAAC,CAAC;gBACH,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,yBAA2B,EAAE;oBAChD,IAAI,EAAE,eAAe;iBACtB,CAAC,CAAC;gBACH,8DAA8D;gBAC9D,8CAA8C;gBAC9C,wDAAwD;gBACxD,MAAM;gBAEN,OAAO,IAAI,CAAC,MAAM,CAAC;aACpB;YAAC,OAAO,GAAG,EAAE;gBACZ,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAC3B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACjB;QACH,CAAC;KAAA;IACK,MAAM,CAAC,IAAa;;YACxB,IAAI;gBACF,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC;gBACjD,OAAO,IAAI,CAAC,MAAM,CAAC;aACpB;YAAC,OAAO,GAAG,EAAE;gBACZ,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAC3B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACjB;QACH,CAAC;KAAA;CACF;AAED,kBAAe,wBAAwB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nimee/initialize-ms",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "init behavior for each ms",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"author": "dan goldberg",
|
|
@@ -10,10 +10,11 @@
|
|
|
10
10
|
"watch-ts": "tsc -w",
|
|
11
11
|
"build": "npm run build-ts",
|
|
12
12
|
"lint": "eslint -c ../../.eslintrc.js --ext .ts src/**",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
13
|
+
"prettier-format": "prettier --config .prettierrc 'src/**/*.ts' --write",
|
|
14
|
+
"publish-it": "npm run build && npm publish --scope=nimee --access public"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
+
"@types/uuid": "^9.0.0",
|
|
17
18
|
"@typescript-eslint/eslint-plugin": "^5.18.0",
|
|
18
19
|
"@typescript-eslint/eslint-plugin-tslint": "^5.18.0",
|
|
19
20
|
"@typescript-eslint/parser": "^5.18.0",
|
|
@@ -21,15 +22,16 @@
|
|
|
21
22
|
"eslint-plugin-jsdoc": "^38.1.6",
|
|
22
23
|
"eslint-plugin-no-null": "^1.0.2",
|
|
23
24
|
"nodemon": "^1.19.1",
|
|
24
|
-
"typescript": "4.
|
|
25
|
+
"typescript": "^4.8.3"
|
|
25
26
|
},
|
|
26
27
|
"types": "dist/src/index.d.ts",
|
|
27
28
|
"dependencies": {
|
|
28
29
|
"@fastify/cors": "^8.1.1",
|
|
30
|
+
"@fastify/request-context": "^4.2.0",
|
|
29
31
|
"@fastify/swagger": "^8.1.0",
|
|
30
|
-
"@nimee/
|
|
31
|
-
"@nimee/
|
|
32
|
+
"@nimee/error-handler": "0.0.3",
|
|
33
|
+
"@nimee/logger": "1.0.21",
|
|
32
34
|
"fastify": "^4.6.0",
|
|
33
35
|
"mongoose": "6.2.10"
|
|
34
36
|
}
|
|
35
|
-
}
|
|
37
|
+
}
|
package/src/fastify.ts
CHANGED
|
@@ -1,15 +1,38 @@
|
|
|
1
|
-
import Fastify, {
|
|
1
|
+
import Fastify, { FastifyRequest } from "fastify";
|
|
2
2
|
import logger from "@nimee/logger";
|
|
3
|
+
import fastifyRequestContextPlugin from "@fastify/request-context";
|
|
4
|
+
import { v4 as uuid } from "uuid";
|
|
5
|
+
|
|
6
|
+
declare module "@fastify/request-context" {
|
|
7
|
+
interface RequestContextData {
|
|
8
|
+
foo: string;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
3
12
|
class ServerInitializerFastify {
|
|
4
13
|
server: any;
|
|
5
14
|
async initialize(serviceName?: string) {
|
|
6
15
|
try {
|
|
7
|
-
this.server = Fastify({
|
|
16
|
+
this.server = Fastify({
|
|
17
|
+
logger,
|
|
18
|
+
requestIdLogLabel: "reqId",
|
|
19
|
+
genReqId(req: FastifyRequest) {
|
|
20
|
+
// you get access to the req here if you need it - must be a synchronous function
|
|
21
|
+
return uuid();
|
|
22
|
+
},
|
|
23
|
+
});
|
|
8
24
|
|
|
9
25
|
this.server.register(require("@fastify/cors"), {
|
|
10
26
|
origin: ["http://localhost:8080", "http://127.0.0.1:8080", "http://localhost:3000"],
|
|
11
27
|
methods: ["GET", "PUT", "PATCH", "POST", "DELETE"],
|
|
12
28
|
});
|
|
29
|
+
this.server.register(fastifyRequestContextPlugin, {
|
|
30
|
+
hook: "preValidation",
|
|
31
|
+
});
|
|
32
|
+
// this.server.addHook("preHandler", async (request: any) => {
|
|
33
|
+
// requestContext.set("user", request.user);
|
|
34
|
+
// logger.info(`1user:${requestContext.get("user")}`);
|
|
35
|
+
// });
|
|
13
36
|
|
|
14
37
|
return this.server;
|
|
15
38
|
} catch (err) {
|