create-phoenixjs 0.1.1 → 0.1.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.
package/package.json
CHANGED
|
@@ -25,11 +25,12 @@ export class MakeMiddlewareCommand extends Command {
|
|
|
25
25
|
|
|
26
26
|
fs.mkdirSync(directory, { recursive: true });
|
|
27
27
|
|
|
28
|
-
const template = `import { Middleware,
|
|
28
|
+
const template = `import type { Middleware, NextFunction, Request } from '@framework/middleware/Middleware';
|
|
29
29
|
|
|
30
30
|
export class ${className} implements Middleware {
|
|
31
|
-
async handle(request: Request, next: NextFunction): Promise<Response
|
|
32
|
-
// middleware logic
|
|
31
|
+
async handle(request: Request, next: NextFunction): Promise<Response> {
|
|
32
|
+
// Add your middleware logic here
|
|
33
|
+
|
|
33
34
|
return next(request);
|
|
34
35
|
}
|
|
35
36
|
}
|
|
@@ -11,7 +11,7 @@ import { FrameworkRequest } from '@framework/http/Request';
|
|
|
11
11
|
import { FrameworkResponse } from '@framework/http/Response';
|
|
12
12
|
import { Router } from '@framework/routing/Router';
|
|
13
13
|
import { Pipeline } from '@framework/middleware/Pipeline';
|
|
14
|
-
import type { MiddlewareHandler, MiddlewareResolvable } from '@framework/middleware/Middleware';
|
|
14
|
+
import type { Middleware, MiddlewareHandler, MiddlewareResolvable } from '@framework/middleware/Middleware';
|
|
15
15
|
import type { RouteMatch } from '@framework/routing/RouteRegistry';
|
|
16
16
|
import type { ControllerConstructor } from '@framework/controller/Controller';
|
|
17
17
|
|
|
@@ -229,15 +229,25 @@ export class Kernel {
|
|
|
229
229
|
// Check for middleware alias
|
|
230
230
|
const aliased = Router.resolveMiddleware(m);
|
|
231
231
|
if (aliased && typeof aliased !== 'string') {
|
|
232
|
-
|
|
232
|
+
// Handle the aliased middleware (could be class or instance)
|
|
233
|
+
if (typeof aliased === 'function' && aliased.prototype && typeof aliased.prototype.handle === 'function') {
|
|
234
|
+
const MiddlewareClass = aliased as new () => Middleware;
|
|
235
|
+
resolved.push(new MiddlewareClass());
|
|
236
|
+
} else {
|
|
237
|
+
resolved.push(aliased as MiddlewareHandler);
|
|
238
|
+
}
|
|
233
239
|
}
|
|
234
240
|
// Check for middleware group
|
|
235
241
|
else if (this.middlewareGroups.has(m)) {
|
|
236
242
|
resolved.push(...(this.middlewareGroups.get(m) || []));
|
|
237
243
|
}
|
|
238
244
|
// String middleware not resolved - skip for now (will be resolved via controller in Phase 2)
|
|
245
|
+
} else if (typeof m === 'function' && m.prototype && typeof m.prototype.handle === 'function') {
|
|
246
|
+
// Handle middleware class constructors (instantiate them)
|
|
247
|
+
const MiddlewareClass = m as new () => Middleware;
|
|
248
|
+
resolved.push(new MiddlewareClass());
|
|
239
249
|
} else {
|
|
240
|
-
resolved.push(m);
|
|
250
|
+
resolved.push(m as MiddlewareHandler);
|
|
241
251
|
}
|
|
242
252
|
}
|
|
243
253
|
|
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
|
|
8
8
|
import { FrameworkRequest } from '@framework/http/Request';
|
|
9
9
|
|
|
10
|
+
// Re-export for convenience in middleware files
|
|
11
|
+
export { FrameworkRequest as Request } from '@framework/http/Request';
|
|
12
|
+
|
|
10
13
|
/**
|
|
11
14
|
* The function signature for the next middleware in the chain
|
|
12
15
|
*/
|
|
@@ -45,6 +48,13 @@ export type MiddlewareHandler =
|
|
|
45
48
|
| ((request: FrameworkRequest, next: NextFunction) => Promise<Response>);
|
|
46
49
|
|
|
47
50
|
/**
|
|
48
|
-
*
|
|
51
|
+
* Middleware class constructor type
|
|
52
|
+
* For passing middleware classes directly (will be instantiated automatically)
|
|
49
53
|
*/
|
|
50
|
-
export type
|
|
54
|
+
export type MiddlewareClass = new (...args: unknown[]) => Middleware;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Type for middleware that can be resolved from string name, class, or instance
|
|
58
|
+
*/
|
|
59
|
+
export type MiddlewareResolvable = string | MiddlewareHandler | MiddlewareClass;
|
|
60
|
+
|