@athenna/http 3.4.0 → 3.4.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.
@@ -57,6 +57,10 @@ export declare class HttpKernel {
57
57
  * Register the exception handler for all request handlers.
58
58
  */
59
59
  registerExceptionHandler(path?: string): Promise<void>;
60
+ /**
61
+ * Register the route file by importing the file.
62
+ */
63
+ registerRoutes(path: string): Promise<void>;
60
64
  /**
61
65
  * Fabricate the named middlewares aliases.
62
66
  */
@@ -10,7 +10,8 @@ import 'reflect-metadata';
10
10
  import { Server } from '#src';
11
11
  import { Log } from '@athenna/logger';
12
12
  import { Config } from '@athenna/config';
13
- import { Exec, Is, Module } from '@athenna/common';
13
+ import { isAbsolute, resolve } from 'node:path';
14
+ import { File, Exec, Is, Module } from '@athenna/common';
14
15
  import { HttpExceptionHandler } from '#src/Handlers/HttpExceptionHandler';
15
16
  const corsPlugin = await Module.safeImport('@fastify/cors');
16
17
  const helmetPlugin = await Module.safeImport('@fastify/helmet');
@@ -156,6 +157,22 @@ export class HttpKernel {
156
157
  const handler = new Handler();
157
158
  Server.setErrorHandler(handler.handle.bind(handler));
158
159
  }
160
+ /**
161
+ * Register the route file by importing the file.
162
+ */
163
+ async registerRoutes(path) {
164
+ if (path.startsWith('#')) {
165
+ await this.resolvePath(path);
166
+ return;
167
+ }
168
+ if (!isAbsolute(path)) {
169
+ path = resolve(path);
170
+ }
171
+ if (!(await File.exists(path))) {
172
+ return;
173
+ }
174
+ await this.resolvePath(path);
175
+ }
159
176
  /**
160
177
  * Fabricate the named middlewares aliases.
161
178
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@athenna/http",
3
- "version": "3.4.0",
3
+ "version": "3.4.2",
4
4
  "description": "The Athenna Http server. Built on top of fastify.",
5
5
  "license": "MIT",
6
6
  "author": "João Lenon <lenon@athenna.io>",
@@ -24,12 +24,11 @@
24
24
  "esm"
25
25
  ],
26
26
  "scripts": {
27
- "node": "cross-env NODE_OPTIONS=\"--experimental-import-meta-resolve\" ts-node",
28
- "build": "npm run node --silent -- bin/build.ts",
29
- "artisan": "npm run node --silent -- bin/artisan.ts",
27
+ "build": "sh node bin/build.ts",
28
+ "artisan": "sh node bin/artisan.ts",
30
29
  "lint:fix": "eslint \"{src,tests}/**/*.ts\" --fix",
31
- "test": "npm run --silent lint:fix && npm run node --silent -- bin/test.ts",
32
- "test:debug": "cross-env DEBUG=api:* npm run node --silent -- bin/test.ts --inspect",
30
+ "test": "npm run --silent lint:fix && sh node bin/test.ts",
31
+ "test:debug": "cross-env DEBUG=api:* sh node --inspect bin/test.ts",
33
32
  "test:coverage": "c8 npm run --silent test"
34
33
  },
35
34
  "files": [
@@ -64,13 +63,13 @@
64
63
  "fastify": "^4.13.0"
65
64
  },
66
65
  "devDependencies": {
67
- "@athenna/artisan": "^3.3.0",
68
- "@athenna/common": "^3.3.3",
69
- "@athenna/config": "^3.2.0",
70
- "@athenna/ioc": "^3.1.5",
71
- "@athenna/logger": "^3.1.5",
72
- "@athenna/test": "^3.2.0",
73
- "@athenna/view": "^3.0.3",
66
+ "@athenna/artisan": "^3.3.3",
67
+ "@athenna/common": "^3.4.2",
68
+ "@athenna/config": "^3.2.1",
69
+ "@athenna/ioc": "^3.1.6",
70
+ "@athenna/logger": "^3.1.6",
71
+ "@athenna/test": "^3.2.2",
72
+ "@athenna/view": "^3.0.5",
74
73
  "@fastify/cors": "^8.1.1",
75
74
  "@fastify/helmet": "^10.0.2",
76
75
  "@fastify/rate-limit": "^7.5.0",
@@ -114,7 +113,7 @@
114
113
  "prettier": "^2.8.3",
115
114
  "reflect-metadata": "^0.1.13",
116
115
  "rimraf": "^3.0.2",
117
- "sinon": "^15.0.1",
116
+ "sinon": "^15.0.2",
118
117
  "ts-node": "^10.9.1",
119
118
  "typescript": "^4.9.4"
120
119
  },