@alterior/fastify 3.15.0 → 3.16.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/dist/event.d.ts +2 -2
- package/dist/event.d.ts.map +1 -1
- package/dist/fastify-engine.d.ts +10 -8
- package/dist/fastify-engine.d.ts.map +1 -1
- package/dist/fastify-engine.js +15 -5
- package/dist/fastify-engine.js.map +1 -1
- package/dist.esm/event.d.ts +2 -2
- package/dist.esm/event.d.ts.map +1 -1
- package/dist.esm/fastify-engine.d.ts +10 -8
- package/dist.esm/fastify-engine.d.ts.map +1 -1
- package/dist.esm/fastify-engine.js +16 -6
- package/dist.esm/fastify-engine.js.map +1 -1
- package/package.json +6 -4
- package/src/fastify-engine.ts +51 -40
package/dist/event.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare class FastifyEvent {
|
|
2
|
-
static get current(): import("
|
|
3
|
-
static get request(): import("
|
|
2
|
+
static get current(): import("@alterior/web-server").RequestBase;
|
|
3
|
+
static get request(): import("@alterior/web-server").RequestBase;
|
|
4
4
|
}
|
|
5
5
|
//# sourceMappingURL=event.d.ts.map
|
package/dist/event.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../src/event.ts"],"names":[],"mappings":"AAEA,qBAAa,YAAY;IACrB,MAAM,KAAK,OAAO
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../src/event.ts"],"names":[],"mappings":"AAEA,qBAAa,YAAY;IACrB,MAAM,KAAK,OAAO,+CAA+B;IACjD,MAAM,KAAK,OAAO,+CAA+B;CACpD"}
|
package/dist/fastify-engine.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { WebEvent, WebServerEngine, ConnectMiddleware } from '@alterior/web-server';
|
|
3
|
-
import * as http from 'http';
|
|
4
|
-
export type FastifyConnectMiddleware = ConnectMiddleware & fastify.FastifyInstance<http.Server, http.IncomingMessage, http.ServerResponse>;
|
|
1
|
+
import { WebEvent, WebServerEngine, ConnectMiddleware, ServerOwnedWebEvent, ConnectApplication } from '@alterior/web-server';
|
|
5
2
|
export declare class FastifyEngine extends WebServerEngine {
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
private server;
|
|
4
|
+
private setup;
|
|
5
|
+
readonly fastify: import("fastify").FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<import("fastify").FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>> & {
|
|
6
|
+
__linterBrands: "SafePromiseLike";
|
|
7
|
+
};
|
|
8
|
+
readonly app: ConnectApplication;
|
|
9
|
+
readonly providers: never[];
|
|
8
10
|
sendJsonBody(routeEvent: WebEvent, body: any): void;
|
|
9
11
|
addConnectMiddleware(path: string, middleware: any): void;
|
|
10
|
-
addRoute(method: string, path: string, handler: (event: WebEvent) => void, middleware?:
|
|
11
|
-
addAnyRoute(handler: (event:
|
|
12
|
+
addRoute(method: string, path: string, handler: (event: WebEvent) => void, middleware?: ConnectMiddleware[]): void;
|
|
13
|
+
addAnyRoute(handler: (event: ServerOwnedWebEvent) => void): void;
|
|
12
14
|
private getRegistrarName;
|
|
13
15
|
}
|
|
14
16
|
//# sourceMappingURL=fastify-engine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastify-engine.d.ts","sourceRoot":"","sources":["../src/fastify-engine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fastify-engine.d.ts","sourceRoot":"","sources":["../src/fastify-engine.ts"],"names":[],"mappings":"AAIA,OAAO,EACH,QAAQ,EAAE,eAAe,EAAE,iBAAiB,EAAE,mBAAmB,EAAa,kBAAkB,EAEnG,MAAM,sBAAsB,CAAC;AAE9B,qBAAa,aAAc,SAAQ,eAAe;IAC9C,OAAO,CAAC,MAAM,CAAqB;IAEnC,OAAO,CAAC,KAAK;IAKb,QAAQ,CAAC,OAAO;;MAAgB;IAChC,QAAQ,CAAC,GAAG,EAAE,kBAAkB,CAA+D;IAC/F,QAAQ,CAAC,SAAS,UAAM;IAEf,YAAY,CAAC,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG;IAM5C,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG;IAIlD,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,EAAE,UAAU,CAAC,EAAE,iBAAiB,EAAE;IAY3G,WAAW,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI;IAIlE,OAAO,CAAC,gBAAgB;CAO3B"}
|
package/dist/fastify-engine.js
CHANGED
|
@@ -2,30 +2,40 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FastifyEngine = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const middie_1 = tslib_1.__importDefault(require("@fastify/middie"));
|
|
5
6
|
const fastify_1 = tslib_1.__importDefault(require("fastify"));
|
|
7
|
+
const di_1 = require("@alterior/di");
|
|
6
8
|
const web_server_1 = require("@alterior/web-server");
|
|
7
9
|
class FastifyEngine extends web_server_1.WebServerEngine {
|
|
8
10
|
constructor() {
|
|
9
11
|
super(...arguments);
|
|
10
|
-
this.
|
|
12
|
+
this.server = (0, di_1.inject)(web_server_1.WebServer);
|
|
13
|
+
this.fastify = this.setup();
|
|
14
|
+
this.app = (req, res) => this.fastify.server.emit('request', req, res);
|
|
11
15
|
this.providers = [];
|
|
12
16
|
}
|
|
17
|
+
setup() {
|
|
18
|
+
let app = (0, fastify_1.default)();
|
|
19
|
+
app.register(middie_1.default);
|
|
20
|
+
return app;
|
|
21
|
+
}
|
|
13
22
|
sendJsonBody(routeEvent, body) {
|
|
14
23
|
routeEvent.response.setHeader('Content-Type', 'application/json');
|
|
15
|
-
routeEvent.response
|
|
24
|
+
routeEvent.response.write(body);
|
|
25
|
+
routeEvent.response.end();
|
|
16
26
|
}
|
|
17
27
|
addConnectMiddleware(path, middleware) {
|
|
18
|
-
this.
|
|
28
|
+
this.fastify.use(path, middleware);
|
|
19
29
|
}
|
|
20
30
|
addRoute(method, path, handler, middleware) {
|
|
21
31
|
if (!middleware)
|
|
22
32
|
middleware = [];
|
|
23
|
-
this.
|
|
33
|
+
this.fastify[this.getRegistrarName(method)](path, ...middleware, (req, res) => {
|
|
24
34
|
return handler(new web_server_1.WebEvent(req, res));
|
|
25
35
|
});
|
|
26
36
|
}
|
|
27
37
|
addAnyRoute(handler) {
|
|
28
|
-
this.
|
|
38
|
+
this.fastify.all('*', (req, res) => handler(this.server.registerEvent(new web_server_1.WebEvent(req, res))));
|
|
29
39
|
}
|
|
30
40
|
getRegistrarName(method) {
|
|
31
41
|
let registrar = method.toLowerCase();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastify-engine.js","sourceRoot":"","sources":["../src/fastify-engine.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"fastify-engine.js","sourceRoot":"","sources":["../src/fastify-engine.ts"],"names":[],"mappings":";;;;AAAA,qEAAqC;AACrC,8DAA8B;AAE9B,qCAAsC;AACtC,qDAG8B;AAE9B,MAAa,aAAc,SAAQ,4BAAe;IAAlD;;QACY,WAAM,GAAG,IAAA,WAAM,EAAC,sBAAS,CAAC,CAAC;QAO1B,YAAO,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;QACvB,QAAG,GAAuB,CAAC,GAAG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AI,qBAAQ,CAAC,GAAU,EAAE,GAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IAClH,CAAC;IAEO,gBAAgB,CAAC,MAAc;QACnC,IAAI,SAAS,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;QACrC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,SAAS,CAAC;YAC1C,MAAM,IAAI,KAAK,CAAC,yBAAyB,MAAM,gCAAgC,CAAC,CAAC;QAErF,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AA7CD,sCA6CC"}
|
package/dist.esm/event.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare class FastifyEvent {
|
|
2
|
-
static get current(): import("
|
|
3
|
-
static get request(): import("
|
|
2
|
+
static get current(): import("@alterior/web-server").RequestBase;
|
|
3
|
+
static get request(): import("@alterior/web-server").RequestBase;
|
|
4
4
|
}
|
|
5
5
|
//# sourceMappingURL=event.d.ts.map
|
package/dist.esm/event.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../src/event.ts"],"names":[],"mappings":"AAEA,qBAAa,YAAY;IACrB,MAAM,KAAK,OAAO
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../src/event.ts"],"names":[],"mappings":"AAEA,qBAAa,YAAY;IACrB,MAAM,KAAK,OAAO,+CAA+B;IACjD,MAAM,KAAK,OAAO,+CAA+B;CACpD"}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { WebEvent, WebServerEngine, ConnectMiddleware } from '@alterior/web-server';
|
|
3
|
-
import * as http from 'http';
|
|
4
|
-
export type FastifyConnectMiddleware = ConnectMiddleware & fastify.FastifyInstance<http.Server, http.IncomingMessage, http.ServerResponse>;
|
|
1
|
+
import { WebEvent, WebServerEngine, ConnectMiddleware, ServerOwnedWebEvent, ConnectApplication } from '@alterior/web-server';
|
|
5
2
|
export declare class FastifyEngine extends WebServerEngine {
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
private server;
|
|
4
|
+
private setup;
|
|
5
|
+
readonly fastify: import("fastify").FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<import("fastify").FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>> & {
|
|
6
|
+
__linterBrands: "SafePromiseLike";
|
|
7
|
+
};
|
|
8
|
+
readonly app: ConnectApplication;
|
|
9
|
+
readonly providers: never[];
|
|
8
10
|
sendJsonBody(routeEvent: WebEvent, body: any): void;
|
|
9
11
|
addConnectMiddleware(path: string, middleware: any): void;
|
|
10
|
-
addRoute(method: string, path: string, handler: (event: WebEvent) => void, middleware?:
|
|
11
|
-
addAnyRoute(handler: (event:
|
|
12
|
+
addRoute(method: string, path: string, handler: (event: WebEvent) => void, middleware?: ConnectMiddleware[]): void;
|
|
13
|
+
addAnyRoute(handler: (event: ServerOwnedWebEvent) => void): void;
|
|
12
14
|
private getRegistrarName;
|
|
13
15
|
}
|
|
14
16
|
//# sourceMappingURL=fastify-engine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastify-engine.d.ts","sourceRoot":"","sources":["../src/fastify-engine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fastify-engine.d.ts","sourceRoot":"","sources":["../src/fastify-engine.ts"],"names":[],"mappings":"AAIA,OAAO,EACH,QAAQ,EAAE,eAAe,EAAE,iBAAiB,EAAE,mBAAmB,EAAa,kBAAkB,EAEnG,MAAM,sBAAsB,CAAC;AAE9B,qBAAa,aAAc,SAAQ,eAAe;IAC9C,OAAO,CAAC,MAAM,CAAqB;IAEnC,OAAO,CAAC,KAAK;IAKb,QAAQ,CAAC,OAAO;;MAAgB;IAChC,QAAQ,CAAC,GAAG,EAAE,kBAAkB,CAA+D;IAC/F,QAAQ,CAAC,SAAS,UAAM;IAEf,YAAY,CAAC,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG;IAM5C,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG;IAIlD,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,EAAE,UAAU,CAAC,EAAE,iBAAiB,EAAE;IAY3G,WAAW,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,IAAI;IAIlE,OAAO,CAAC,gBAAgB;CAO3B"}
|
|
@@ -1,27 +1,37 @@
|
|
|
1
|
+
import middie from '@fastify/middie';
|
|
1
2
|
import fastify from "fastify";
|
|
2
|
-
import {
|
|
3
|
+
import { inject } from "@alterior/di";
|
|
4
|
+
import { WebEvent, WebServerEngine, WebServer } from '@alterior/web-server';
|
|
3
5
|
export class FastifyEngine extends WebServerEngine {
|
|
4
6
|
constructor() {
|
|
5
7
|
super(...arguments);
|
|
6
|
-
this.
|
|
8
|
+
this.server = inject(WebServer);
|
|
9
|
+
this.fastify = this.setup();
|
|
10
|
+
this.app = (req, res) => this.fastify.server.emit('request', req, res);
|
|
7
11
|
this.providers = [];
|
|
8
12
|
}
|
|
13
|
+
setup() {
|
|
14
|
+
let app = fastify();
|
|
15
|
+
app.register(middie);
|
|
16
|
+
return app;
|
|
17
|
+
}
|
|
9
18
|
sendJsonBody(routeEvent, body) {
|
|
10
19
|
routeEvent.response.setHeader('Content-Type', 'application/json');
|
|
11
|
-
routeEvent.response
|
|
20
|
+
routeEvent.response.write(body);
|
|
21
|
+
routeEvent.response.end();
|
|
12
22
|
}
|
|
13
23
|
addConnectMiddleware(path, middleware) {
|
|
14
|
-
this.
|
|
24
|
+
this.fastify.use(path, middleware);
|
|
15
25
|
}
|
|
16
26
|
addRoute(method, path, handler, middleware) {
|
|
17
27
|
if (!middleware)
|
|
18
28
|
middleware = [];
|
|
19
|
-
this.
|
|
29
|
+
this.fastify[this.getRegistrarName(method)](path, ...middleware, (req, res) => {
|
|
20
30
|
return handler(new WebEvent(req, res));
|
|
21
31
|
});
|
|
22
32
|
}
|
|
23
33
|
addAnyRoute(handler) {
|
|
24
|
-
this.
|
|
34
|
+
this.fastify.all('*', (req, res) => handler(this.server.registerEvent(new WebEvent(req, res))));
|
|
25
35
|
}
|
|
26
36
|
getRegistrarName(method) {
|
|
27
37
|
let registrar = method.toLowerCase();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastify-engine.js","sourceRoot":"","sources":["../src/fastify-engine.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"fastify-engine.js","sourceRoot":"","sources":["../src/fastify-engine.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EACH,QAAQ,EAAE,eAAe,EAA0C,SAAS,EAE/E,MAAM,sBAAsB,CAAC;AAE9B,MAAM,OAAO,aAAc,SAAQ,eAAe;IAAlD;;QACY,WAAM,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;QAO1B,YAAO,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;QACvB,QAAG,GAAuB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QACtF,cAAS,GAAG,EAAE,CAAC;IAmC5B,CAAC;IA1CW,KAAK;QACT,IAAI,GA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QAAQ,CAAC,SAAS,CAAC;YAC1C,MAAM,IAAI,KAAK,CAAC,yBAAyB,MAAM,gCAAgC,CAAC,CAAC;QAErF,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alterior/fastify",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.16.0",
|
|
4
4
|
"description": "Access Fastify state within an Alterior app",
|
|
5
5
|
"author": "The Alterior Project (https://github.com/alterior-mvc)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,9 +37,11 @@
|
|
|
37
37
|
"docs": "typedoc src/index.ts"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@alterior/
|
|
41
|
-
"@alterior/
|
|
42
|
-
"
|
|
40
|
+
"@alterior/di": "^3.16.0",
|
|
41
|
+
"@alterior/logging": "^3.16.0",
|
|
42
|
+
"@alterior/web-server": "^3.16.0",
|
|
43
|
+
"@fastify/middie": "^9.3.2",
|
|
44
|
+
"fastify": "^5.8.5"
|
|
43
45
|
},
|
|
44
46
|
"gitHead": "87f31ea4078faaca53b45573c6a0013cdb40dd07"
|
|
45
47
|
}
|
package/src/fastify-engine.ts
CHANGED
|
@@ -1,44 +1,55 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import middie from '@fastify/middie';
|
|
2
|
+
import fastify from "fastify";
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import { inject } from "@alterior/di";
|
|
5
|
+
import {
|
|
6
|
+
WebEvent, WebServerEngine, ConnectMiddleware, ServerOwnedWebEvent, WebServer, ConnectApplication,
|
|
7
|
+
RequestBase, ResponseBase
|
|
8
|
+
} from '@alterior/web-server';
|
|
7
9
|
|
|
8
10
|
export class FastifyEngine extends WebServerEngine {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
11
|
+
private server = inject(WebServer);
|
|
12
|
+
|
|
13
|
+
private setup() {
|
|
14
|
+
let app = fastify();
|
|
15
|
+
app.register(middie);
|
|
16
|
+
return app;
|
|
17
|
+
}
|
|
18
|
+
readonly fastify = this.setup();
|
|
19
|
+
readonly app: ConnectApplication = (req, res) => this.fastify.server.emit('request', req, res);
|
|
20
|
+
readonly providers = [];
|
|
21
|
+
|
|
22
|
+
override sendJsonBody(routeEvent: WebEvent, body: any) {
|
|
23
|
+
routeEvent.response.setHeader('Content-Type', 'application/json');
|
|
24
|
+
routeEvent.response.write(body);
|
|
25
|
+
routeEvent.response.end();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
override addConnectMiddleware(path: string, middleware: any) {
|
|
29
|
+
this.fastify.use(path, middleware);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
override addRoute(method: string, path: string, handler: (event: WebEvent) => void, middleware?: ConnectMiddleware[]) {
|
|
33
|
+
if (!middleware)
|
|
34
|
+
middleware = [];
|
|
35
|
+
(this.fastify as any)[this.getRegistrarName(method)](
|
|
36
|
+
path,
|
|
37
|
+
...middleware,
|
|
38
|
+
(req: RequestBase, res: ResponseBase) => {
|
|
39
|
+
return handler(new WebEvent(req, res));
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
override addAnyRoute(handler: (event: ServerOwnedWebEvent) => void) {
|
|
45
|
+
this.fastify.all('*', (req, res) => handler(this.server.registerEvent(new WebEvent(req as any, res as any))));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private getRegistrarName(method: string) {
|
|
49
|
+
let registrar = method.toLowerCase();
|
|
50
|
+
if (!this.supportedMethods.includes(registrar))
|
|
51
|
+
throw new Error(`The specified method '${method}' is not supported by Express.`);
|
|
52
|
+
|
|
53
|
+
return registrar;
|
|
54
|
+
}
|
|
44
55
|
}
|