@athenna/http 3.4.0 → 3.4.1

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.1",
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>",