@webtypen/webframez-core 0.3.70 → 0.3.71
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/README.md +5 -0
- package/dist/Api/ApiScope.d.ts +2 -0
- package/dist/Api/ApiScope.js +2 -0
- package/dist/Api/ApiScopeRegistry.js +3 -3
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -370,6 +370,11 @@ Example: `GET /api/backoffice/current-user`.
|
|
|
370
370
|
|
|
371
371
|
The scope middleware runs before the function. Its return value is passed to the function as `apiRequest.context`. Calling `abort(message, status)` stops execution and returns an error response with that status.
|
|
372
372
|
|
|
373
|
+
For HTTP middleware that must also run on automatic `OPTIONS` responses, set
|
|
374
|
+
`routeMiddleware = ["cors"]` on the scope. These names refer to middleware in the
|
|
375
|
+
application kernel. They run before the route handler; scope `middleware()` still
|
|
376
|
+
runs for function calls and provides their authorization/context (including MCP).
|
|
377
|
+
|
|
373
378
|
### Group ApiScopes
|
|
374
379
|
|
|
375
380
|
Use `ApiScopesGroup` to share middleware across multiple scopes:
|
package/dist/Api/ApiScope.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export declare class ApiScope {
|
|
|
5
5
|
key: string;
|
|
6
6
|
apiBasePath: string | null;
|
|
7
7
|
mcpEndpoint: string | null;
|
|
8
|
+
/** Kernel middleware for HTTP routes, including automatic OPTIONS responses. */
|
|
9
|
+
routeMiddleware: string[];
|
|
8
10
|
functions: Array<ApiFunctionClass> | (() => Array<ApiFunctionClass>);
|
|
9
11
|
middleware(_req: Request, _res: Response, _abort: ApiScopeMiddlewareAbort): Promise<{
|
|
10
12
|
[key: string]: any;
|
package/dist/Api/ApiScope.js
CHANGED
|
@@ -15,6 +15,8 @@ class ApiScope {
|
|
|
15
15
|
this.key = "unique_scope_key";
|
|
16
16
|
this.apiBasePath = "/api";
|
|
17
17
|
this.mcpEndpoint = null;
|
|
18
|
+
/** Kernel middleware for HTTP routes, including automatic OPTIONS responses. */
|
|
19
|
+
this.routeMiddleware = [];
|
|
18
20
|
this.functions = [];
|
|
19
21
|
}
|
|
20
22
|
middleware(_req, _res, _abort) {
|
|
@@ -71,10 +71,10 @@ class ApiScopeRegistryFacade {
|
|
|
71
71
|
const handler = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
72
72
|
return yield this.handleHttpFunction(registration, FunctionClass, req, res);
|
|
73
73
|
});
|
|
74
|
-
this.registerRouteMethod(func.requestMethod, path, handler);
|
|
74
|
+
this.registerRouteMethod(func.requestMethod, path, handler, scope.routeMiddleware);
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
registerRouteMethod(method, path, handler) {
|
|
77
|
+
registerRouteMethod(method, path, handler, middleware) {
|
|
78
78
|
if (!method) {
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
@@ -83,7 +83,7 @@ class ApiScopeRegistryFacade {
|
|
|
83
83
|
if (!routeMethod || typeof routeMethod !== "function") {
|
|
84
84
|
throw new Error(`ApiFunction request method "${method}" is not supported by Route`);
|
|
85
85
|
}
|
|
86
|
-
routeMethod.bind(Route_1.Route)(path, handler);
|
|
86
|
+
routeMethod.bind(Route_1.Route)(path, handler, { middleware });
|
|
87
87
|
}
|
|
88
88
|
handleHttpFunction(registration, FunctionClass, req, res) {
|
|
89
89
|
return __awaiter(this, void 0, void 0, function* () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webtypen/webframez-core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.71",
|
|
4
4
|
"description": "The core package of the typescript based webframez (web-framework) by webtypen.de",
|
|
5
5
|
"homepage": "https://webtypen.de/",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "tsc",
|
|
33
33
|
"build:check": "tsc --noEmit",
|
|
34
|
-
"dev": "PORT=3210 ts-node ./dev/app.ts"
|
|
34
|
+
"dev": "PORT=3210 ts-node ./dev/app.ts",
|
|
35
|
+
"test": "node --test tests/*.test.cjs"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"@types/busboy": "^1.5.4",
|