@vorplex/api 0.0.79 → 0.0.81
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/dist/client/tsconfig.build.tsbuildinfo +1 -1
- package/dist/server/index.d.ts +0 -1
- package/dist/server/index.js +0 -1
- package/dist/server/server/controller/controller.interface.d.ts +11 -3
- package/dist/server/server/controller/handler.interface.d.ts +1 -3
- package/dist/server/server/server.model.js +4 -16
- package/dist/server/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/dist/server/server/controller/guard.type.d.ts +0 -10
- package/dist/server/server/controller/guard.type.js +0 -0
package/dist/server/index.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
export * from './jwt.util';
|
|
3
3
|
export * from './server/server.model';
|
|
4
4
|
export * from './server/controller/controller.interface';
|
|
5
|
-
export * from './server/controller/guard.type';
|
|
6
5
|
export * from './server/controller/handler.interface';
|
|
7
6
|
export * from './server/http/error.model';
|
|
8
7
|
export * from './server/http/reader.util';
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Awaitable, Injector } from '@vorplex/core';
|
|
2
|
+
import { Server } from '../server.model';
|
|
2
3
|
import { Handler } from './handler.interface';
|
|
4
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
5
|
+
export type ControllerGuard = (params: {
|
|
6
|
+
injector: Injector;
|
|
7
|
+
server: Server;
|
|
8
|
+
request: IncomingMessage;
|
|
9
|
+
response: ServerResponse;
|
|
10
|
+
}) => Awaitable<boolean>;
|
|
3
11
|
export interface Controller {
|
|
4
12
|
route: string;
|
|
5
|
-
guards?:
|
|
6
|
-
handlers
|
|
13
|
+
guards?: ControllerGuard[];
|
|
14
|
+
handlers: Handler[];
|
|
7
15
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Awaitable, ExtractRouteParams, Injector, Task } from '@vorplex/core';
|
|
2
|
-
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
2
|
import { HttpRequestMethod } from '../http/request-method.enum';
|
|
3
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
4
4
|
import { HttpResponses } from '../http/response.interface';
|
|
5
5
|
import { Server } from '../server.model';
|
|
6
|
-
import { Guard } from './guard.type';
|
|
7
6
|
type QueryKeys<T extends readonly string[]> = {
|
|
8
7
|
[K in T[number] as K extends `${string}?` ? never : K]: string;
|
|
9
8
|
} & {
|
|
@@ -24,7 +23,6 @@ export interface Handler<TRoute extends string = string, TParameters extends str
|
|
|
24
23
|
route: TRoute;
|
|
25
24
|
parameters?: TParameters;
|
|
26
25
|
method: HttpRequestMethod;
|
|
27
|
-
guards?: Guard[];
|
|
28
26
|
callback: (params: HandlerParams<ExtractRouteParams<TRoute>, TParameters>) => Awaitable<HttpResponses | void>;
|
|
29
27
|
}
|
|
30
28
|
export {};
|
|
@@ -84,8 +84,8 @@ export class Server {
|
|
|
84
84
|
for (const controller of this.controllers) {
|
|
85
85
|
for (const handler of controller.handlers) {
|
|
86
86
|
if (handler.method === request.method) {
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
87
|
+
const match = $Router.match(`${controller.route}${handler.route}`, request.url);
|
|
88
|
+
if (match) {
|
|
89
89
|
const query = $Router.getQueryParameters(request.url);
|
|
90
90
|
task.log(`Forwarding request to controller (${controller.route}) handler (${handler.route})`);
|
|
91
91
|
for (const guard of controller.guards ?? []) {
|
|
@@ -93,19 +93,7 @@ export class Server {
|
|
|
93
93
|
injector: this.injector,
|
|
94
94
|
server: this,
|
|
95
95
|
request,
|
|
96
|
-
response
|
|
97
|
-
routeParameters
|
|
98
|
-
});
|
|
99
|
-
if (!authorized)
|
|
100
|
-
throw new HttpError(HttpResponseCodes.Unauthorized);
|
|
101
|
-
}
|
|
102
|
-
for (const guard of handler.guards ?? []) {
|
|
103
|
-
const authorized = await guard({
|
|
104
|
-
injector: this.injector,
|
|
105
|
-
server: this,
|
|
106
|
-
request,
|
|
107
|
-
response,
|
|
108
|
-
routeParameters
|
|
96
|
+
response
|
|
109
97
|
});
|
|
110
98
|
if (!authorized)
|
|
111
99
|
throw new HttpError(HttpResponseCodes.Unauthorized);
|
|
@@ -125,7 +113,7 @@ export class Server {
|
|
|
125
113
|
server: this,
|
|
126
114
|
task,
|
|
127
115
|
parameters: {
|
|
128
|
-
route:
|
|
116
|
+
route: match,
|
|
129
117
|
query
|
|
130
118
|
},
|
|
131
119
|
request,
|