@shadow-library/fastify 0.0.1 → 0.0.2

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.
@@ -4,5 +4,7 @@ exports.HttpController = HttpController;
4
4
  const app_1 = require("@shadow-library/app");
5
5
  const constants_1 = require("../constants.js");
6
6
  function HttpController(path = '') {
7
+ if (path.charAt(0) !== '/')
8
+ path = `/${path}`;
7
9
  return target => (0, app_1.Controller)({ [constants_1.HTTP_CONTROLLER_TYPE]: 'router', path })(target);
8
10
  }
@@ -15,6 +15,8 @@ var HttpMethod;
15
15
  HttpMethod["ALL"] = "ALL";
16
16
  })(HttpMethod || (exports.HttpMethod = HttpMethod = {}));
17
17
  function HttpRoute(options) {
18
+ if (options.path && options.path.charAt(0) !== '/')
19
+ options.path = `/${options.path}`;
18
20
  return (0, app_1.Route)(options);
19
21
  }
20
22
  const Get = (path) => HttpRoute({ method: HttpMethod.GET, path });
@@ -52,12 +52,12 @@ let FastifyRouter = FastifyRouter_1 = class FastifyRouter extends app_1.Router {
52
52
  switch (controller.metadata[constants_1.HTTP_CONTROLLER_TYPE]) {
53
53
  case 'router': {
54
54
  const { instance, metadata, metatype } = controller;
55
- const basePath = metadata.path ?? '';
55
+ const basePath = metadata.path ?? '/';
56
56
  for (const route of controller.routes) {
57
57
  const routePath = route.metadata.path ?? '';
58
58
  const path = basePath + routePath;
59
59
  const parsedController = { ...route, instance, metatype };
60
- parsedController.metadata.path = path || '/';
60
+ parsedController.metadata.path = path;
61
61
  parsedControllers.routes.push(parsedController);
62
62
  }
63
63
  break;
@@ -19,6 +19,7 @@ class FastifyModule {
19
19
  responseSchema: { '4xx': errorResponseSchema, '5xx': errorResponseSchema },
20
20
  errorHandler: new classes_1.DefaultErrorHandler(),
21
21
  ignoreTrailingSlash: true,
22
+ ignoreDuplicateSlashes: true,
22
23
  requestIdLogLabel: 'rid',
23
24
  genReqId: () => (0, uuid_1.v4)(),
24
25
  ajv: { customOptions: { removeAdditional: true, useDefaults: true, allErrors: true } },
@@ -1,5 +1,7 @@
1
1
  import { Controller } from '@shadow-library/app';
2
2
  import { HTTP_CONTROLLER_TYPE } from '../constants.js';
3
3
  export function HttpController(path = '') {
4
+ if (path.charAt(0) !== '/')
5
+ path = `/${path}`;
4
6
  return target => Controller({ [HTTP_CONTROLLER_TYPE]: 'router', path })(target);
5
7
  }
@@ -11,6 +11,8 @@ export var HttpMethod;
11
11
  HttpMethod["ALL"] = "ALL";
12
12
  })(HttpMethod || (HttpMethod = {}));
13
13
  export function HttpRoute(options) {
14
+ if (options.path && options.path.charAt(0) !== '/')
15
+ options.path = `/${options.path}`;
14
16
  return Route(options);
15
17
  }
16
18
  export const Get = (path) => HttpRoute({ method: HttpMethod.GET, path });
@@ -46,12 +46,12 @@ let FastifyRouter = FastifyRouter_1 = class FastifyRouter extends Router {
46
46
  switch (controller.metadata[HTTP_CONTROLLER_TYPE]) {
47
47
  case 'router': {
48
48
  const { instance, metadata, metatype } = controller;
49
- const basePath = metadata.path ?? '';
49
+ const basePath = metadata.path ?? '/';
50
50
  for (const route of controller.routes) {
51
51
  const routePath = route.metadata.path ?? '';
52
52
  const path = basePath + routePath;
53
53
  const parsedController = { ...route, instance, metatype };
54
- parsedController.metadata.path = path || '/';
54
+ parsedController.metadata.path = path;
55
55
  parsedControllers.routes.push(parsedController);
56
56
  }
57
57
  break;
@@ -16,6 +16,7 @@ export class FastifyModule {
16
16
  responseSchema: { '4xx': errorResponseSchema, '5xx': errorResponseSchema },
17
17
  errorHandler: new DefaultErrorHandler(),
18
18
  ignoreTrailingSlash: true,
19
+ ignoreDuplicateSlashes: true,
19
20
  requestIdLogLabel: 'rid',
20
21
  genReqId: () => uuid(),
21
22
  ajv: { customOptions: { removeAdditional: true, useDefaults: true, allErrors: true } },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shadow-library/fastify",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "description": "A Fastify wrapper featuring decorator-based routing, middleware and error handling",
6
6
  "repository": {
7
7
  "type": "git",