@athenna/http 4.8.0 → 4.9.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@athenna/http",
3
- "version": "4.8.0",
3
+ "version": "4.9.0",
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>",
@@ -67,12 +67,12 @@
67
67
  "#tests": "./tests/index.js"
68
68
  },
69
69
  "devDependencies": {
70
- "@athenna/artisan": "^4.10.0",
71
- "@athenna/common": "^4.11.0",
70
+ "@athenna/artisan": "^4.12.0",
71
+ "@athenna/common": "^4.15.4",
72
72
  "@athenna/config": "^4.4.0",
73
- "@athenna/ioc": "^4.4.0",
74
- "@athenna/logger": "^4.4.0",
75
- "@athenna/test": "^4.7.0",
73
+ "@athenna/ioc": "^4.4.3",
74
+ "@athenna/logger": "^4.5.0",
75
+ "@athenna/test": "^4.8.0",
76
76
  "@athenna/view": "^4.3.0",
77
77
  "@fastify/cors": "^8.1.1",
78
78
  "@fastify/helmet": "^10.0.2",
@@ -201,9 +201,6 @@
201
201
  "terminator": "./templates/terminator.edge",
202
202
  "command": "@athenna/artisan/templates/command.edge"
203
203
  },
204
- "preloads": [],
205
- "services": [],
206
- "providers": [],
207
204
  "controllers": [
208
205
  "#tests/fixtures/controllers/HelloController",
209
206
  "#tests/fixtures/controllers/AnnotatedController"
@@ -227,17 +224,6 @@
227
224
  "#tests/fixtures/middlewares/AnnotatedGlobalMiddleware",
228
225
  "#tests/fixtures/middlewares/AnnotatedGlobalInterceptor",
229
226
  "#tests/fixtures/middlewares/AnnotatedGlobalTerminator"
230
- ],
231
- "commands": {
232
- "route:list": {
233
- "path": "#src/commands/RouteListCommand",
234
- "route": "./tests/fixtures/routes/http.js",
235
- "kernel": "./tests/fixtures/kernels/HttpKernel.js"
236
- },
237
- "make:controller": "#src/commands/MakeControllerCommand",
238
- "make:interceptor": "#src/commands/MakeInterceptorCommand",
239
- "make:middleware": "#src/commands/MakeMiddlewareCommand",
240
- "make:terminator": "#src/commands/MakeTerminatorCommand"
241
- }
227
+ ]
242
228
  }
243
229
  }
@@ -19,4 +19,8 @@ export declare class RouteListCommand extends BaseCommand {
19
19
  * Get the http kernel module from RC file or resolve the default one.
20
20
  */
21
21
  private getHttpKernel;
22
+ /**
23
+ * Get the meta URL of the project.
24
+ */
25
+ private getMeta;
22
26
  }
@@ -6,6 +6,7 @@
6
6
  * For the full copyright and license information, please view the LICENSE
7
7
  * file that was distributed with this source code.
8
8
  */
9
+ import { sep } from 'node:path';
9
10
  import { Config } from '@athenna/config';
10
11
  import { Module } from '@athenna/common';
11
12
  import { BaseCommand } from '@athenna/artisan';
@@ -45,7 +46,7 @@ export class RouteListCommand extends BaseCommand {
45
46
  * Resolve the http routes file.
46
47
  */
47
48
  async resolveRoute() {
48
- await Module.resolve(Config.get('rc.commands.route:list.route', '#routes/http'), Config.get('rc.meta'));
49
+ await Module.resolve(Config.get('rc.commands.route:list.route', '#routes/http'), this.getMeta());
49
50
  }
50
51
  /**
51
52
  * Get the http kernel module from RC file or resolve the default one.
@@ -54,6 +55,12 @@ export class RouteListCommand extends BaseCommand {
54
55
  if (!Config.exists('rc.commands.route:list.kernel')) {
55
56
  return HttpKernel;
56
57
  }
57
- return Module.resolve(Config.get('rc.commands.route:list.kernel'), Config.get('rc.meta'));
58
+ return Module.resolve(Config.get('rc.commands.route:list.kernel'), this.getMeta());
59
+ }
60
+ /**
61
+ * Get the meta URL of the project.
62
+ */
63
+ getMeta() {
64
+ return Config.get('rc.meta', Path.toHref(Path.pwd() + sep));
58
65
  }
59
66
  }
@@ -70,10 +70,6 @@ export declare class HttpKernel {
70
70
  * server methods.
71
71
  */
72
72
  private getGlobalMiddlewareAliasAndHandler;
73
- /**
74
- * Resolve the import path by meta URL and import it.
75
- */
76
- private resolvePath;
77
73
  /**
78
74
  * Register the controllers using the meta information
79
75
  * defined by annotations.
@@ -83,4 +79,8 @@ export declare class HttpKernel {
83
79
  * Get the configuration for the given key.
84
80
  */
85
81
  private getConfig;
82
+ /**
83
+ * Get the meta URL of the project.
84
+ */
85
+ private getMeta;
86
86
  }
@@ -11,7 +11,7 @@ import { Server } from '#src';
11
11
  import { debug } from '#src/debug';
12
12
  import { Log } from '@athenna/logger';
13
13
  import { Config } from '@athenna/config';
14
- import { isAbsolute, resolve } from 'node:path';
14
+ import { sep, isAbsolute, resolve } from 'node:path';
15
15
  import { Annotation } from '@athenna/ioc';
16
16
  import { File, Exec, Module, String } from '@athenna/common';
17
17
  import { HttpExceptionHandler } from '#src/handlers/HttpExceptionHandler';
@@ -117,7 +117,7 @@ export class HttpKernel {
117
117
  async registerControllers() {
118
118
  const controllers = Config.get('rc.controllers', []);
119
119
  await Exec.concurrently(controllers, async (path) => {
120
- const Controller = await this.resolvePath(path);
120
+ const Controller = await Module.resolve(path, this.getMeta());
121
121
  if (Annotation.isAnnotated(Controller)) {
122
122
  this.registerUsingMeta(Controller);
123
123
  return;
@@ -133,7 +133,7 @@ export class HttpKernel {
133
133
  async registerMiddlewares() {
134
134
  const middlewares = Config.get('rc.middlewares', []);
135
135
  await Exec.concurrently(middlewares, async (path) => {
136
- const Middleware = await this.resolvePath(path);
136
+ const Middleware = await Module.resolve(path, this.getMeta());
137
137
  if (Annotation.isAnnotated(Middleware)) {
138
138
  this.registerUsingMeta(Middleware);
139
139
  return;
@@ -152,7 +152,7 @@ export class HttpKernel {
152
152
  async registerNamedMiddlewares() {
153
153
  const namedMiddlewares = Config.get('rc.namedMiddlewares', {});
154
154
  await Exec.concurrently(Object.keys(namedMiddlewares), async (key) => {
155
- const Middleware = await this.resolvePath(namedMiddlewares[key]);
155
+ const Middleware = await Module.resolve(namedMiddlewares[key], this.getMeta());
156
156
  if (Annotation.isAnnotated(Middleware)) {
157
157
  this.registerUsingMeta(Middleware);
158
158
  return;
@@ -168,7 +168,7 @@ export class HttpKernel {
168
168
  async registerGlobalMiddlewares() {
169
169
  const globalMiddlewares = Config.get('rc.globalMiddlewares', []);
170
170
  await Exec.concurrently(globalMiddlewares, async (path) => {
171
- const Middleware = await this.resolvePath(path);
171
+ const Middleware = await Module.resolve(path, this.getMeta());
172
172
  if (Annotation.isAnnotated(Middleware)) {
173
173
  this.registerUsingMeta(Middleware);
174
174
  return;
@@ -191,7 +191,7 @@ export class HttpKernel {
191
191
  Server.setErrorHandler(handler.handle.bind(handler));
192
192
  return;
193
193
  }
194
- const Handler = await this.resolvePath(path);
194
+ const Handler = await Module.resolve(path, this.getMeta());
195
195
  debug('Using custom exception handler %s in HttpKernel.', Handler.name);
196
196
  const handler = new Handler();
197
197
  Server.setErrorHandler(handler.handle.bind(handler));
@@ -201,7 +201,7 @@ export class HttpKernel {
201
201
  */
202
202
  async registerRoutes(path) {
203
203
  if (path.startsWith('#')) {
204
- await this.resolvePath(path);
204
+ await Module.resolve(path, this.getMeta());
205
205
  return;
206
206
  }
207
207
  if (!isAbsolute(path)) {
@@ -210,7 +210,7 @@ export class HttpKernel {
210
210
  if (!(await File.exists(path))) {
211
211
  return;
212
212
  }
213
- await this.resolvePath(path);
213
+ await Module.resolve(path, this.getMeta());
214
214
  }
215
215
  /**
216
216
  * Fabricate the named middlewares aliases.
@@ -264,12 +264,6 @@ export class HttpKernel {
264
264
  };
265
265
  }
266
266
  }
267
- /**
268
- * Resolve the import path by meta URL and import it.
269
- */
270
- resolvePath(path) {
271
- return Module.resolve(`${path}?version=${Math.random()}`, Config.get('rc.meta'));
272
- }
273
267
  /**
274
268
  * Register the controllers using the meta information
275
269
  * defined by annotations.
@@ -302,4 +296,10 @@ export class HttpKernel {
302
296
  }
303
297
  return config;
304
298
  }
299
+ /**
300
+ * Get the meta URL of the project.
301
+ */
302
+ getMeta() {
303
+ return Config.get('rc.meta', Path.toHref(Path.pwd() + sep));
304
+ }
305
305
  }