@wooksjs/event-http 0.3.0 → 0.3.1
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 +1 -1
- package/dist/index.cjs +45 -1
- package/dist/index.d.ts +44 -0
- package/dist/index.mjs +45 -1
- package/package.json +3 -3
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -12,6 +12,10 @@ function createHttpContext(data, options) {
|
|
|
12
12
|
options,
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Wrapper on useEventContext with HTTP event types
|
|
17
|
+
* @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
|
|
18
|
+
*/
|
|
15
19
|
function useHttpContext() {
|
|
16
20
|
return eventCore.useEventContext('HTTP');
|
|
17
21
|
}
|
|
@@ -832,7 +836,7 @@ class HttpErrorRenderer extends BaseHttpResponseRenderer {
|
|
|
832
836
|
`<head><title>${data.statusCode} ${httpStatusCodes[data.statusCode]}</title></head>` +
|
|
833
837
|
`<body><center><h1>${data.statusCode} ${httpStatusCodes[data.statusCode]}</h1></center>` +
|
|
834
838
|
`<center><h4>${data.message}</h1></center><hr color="#666">` +
|
|
835
|
-
`<center style="color: #666;"> Wooks v${"0.3.
|
|
839
|
+
`<center style="color: #666;"> Wooks v${"0.3.1"} </center>` +
|
|
836
840
|
`${keys.length
|
|
837
841
|
? `<pre style="${preStyles}">${JSON.stringify(Object.assign(Object.assign({}, data), { statusCode: undefined, message: undefined, error: undefined }), null, ' ')}</pre>`
|
|
838
842
|
: ''}` +
|
|
@@ -973,6 +977,11 @@ class WooksHttp extends wooks.WooksAdapterBase {
|
|
|
973
977
|
options(path, handler) {
|
|
974
978
|
return this.on('OPTIONS', path, handler);
|
|
975
979
|
}
|
|
980
|
+
/**
|
|
981
|
+
* Starts the http(s) server.
|
|
982
|
+
*
|
|
983
|
+
* Use this only if you rely on Wooks server.
|
|
984
|
+
*/
|
|
976
985
|
listen(...args) {
|
|
977
986
|
return __awaiter(this, void 0, void 0, function* () {
|
|
978
987
|
const server = (this.server = http.createServer(this.getServerCb()));
|
|
@@ -983,6 +992,10 @@ class WooksHttp extends wooks.WooksAdapterBase {
|
|
|
983
992
|
});
|
|
984
993
|
});
|
|
985
994
|
}
|
|
995
|
+
/**
|
|
996
|
+
* Stops the server if it was attached or passed via argument
|
|
997
|
+
* @param server
|
|
998
|
+
*/
|
|
986
999
|
close(server) {
|
|
987
1000
|
const srv = server || this.server;
|
|
988
1001
|
return new Promise((resolve, reject) => {
|
|
@@ -993,9 +1006,22 @@ class WooksHttp extends wooks.WooksAdapterBase {
|
|
|
993
1006
|
});
|
|
994
1007
|
});
|
|
995
1008
|
}
|
|
1009
|
+
/**
|
|
1010
|
+
* Returns http(s) server that was attached to Wooks
|
|
1011
|
+
*
|
|
1012
|
+
* See attachServer method docs
|
|
1013
|
+
* @returns Server
|
|
1014
|
+
*/
|
|
996
1015
|
getServer() {
|
|
997
1016
|
return this.server;
|
|
998
1017
|
}
|
|
1018
|
+
/**
|
|
1019
|
+
* Attaches http(s) server instance
|
|
1020
|
+
* to Wooks.
|
|
1021
|
+
*
|
|
1022
|
+
* Use it only if you want to `close` method to stop the server.
|
|
1023
|
+
* @param server Server
|
|
1024
|
+
*/
|
|
999
1025
|
attachServer(server) {
|
|
1000
1026
|
this.server = server;
|
|
1001
1027
|
}
|
|
@@ -1005,6 +1031,18 @@ class WooksHttp extends wooks.WooksAdapterBase {
|
|
|
1005
1031
|
this.logger.error('Uncought response exception', e);
|
|
1006
1032
|
}));
|
|
1007
1033
|
}
|
|
1034
|
+
/**
|
|
1035
|
+
* Returns server callback function
|
|
1036
|
+
* that can be passed to any node server:
|
|
1037
|
+
* ```js
|
|
1038
|
+
* import { createHttpApp } from '@wooksjs/event-http'
|
|
1039
|
+
* import http from 'http'
|
|
1040
|
+
*
|
|
1041
|
+
* const app = createHttpApp()
|
|
1042
|
+
* const server = http.createServer(app.getServerCb())
|
|
1043
|
+
* server.listen(3000)
|
|
1044
|
+
* ```
|
|
1045
|
+
*/
|
|
1008
1046
|
getServerCb() {
|
|
1009
1047
|
return (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
1010
1048
|
var _a, _b, _c;
|
|
@@ -1058,6 +1096,12 @@ class WooksHttp extends wooks.WooksAdapterBase {
|
|
|
1058
1096
|
});
|
|
1059
1097
|
}
|
|
1060
1098
|
}
|
|
1099
|
+
/**
|
|
1100
|
+
* Factory for WooksHttp App
|
|
1101
|
+
* @param opts TWooksHttpOptions
|
|
1102
|
+
* @param wooks Wooks | WooksAdapterBase
|
|
1103
|
+
* @returns WooksHttp
|
|
1104
|
+
*/
|
|
1061
1105
|
function createHttpApp(opts, wooks) {
|
|
1062
1106
|
return new WooksHttp(opts, wooks);
|
|
1063
1107
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -47,6 +47,12 @@ export declare class BaseHttpResponseRenderer<T = unknown> implements TWooksResp
|
|
|
47
47
|
render(response: BaseHttpResponse<T>): string | Uint8Array;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Factory for WooksHttp App
|
|
52
|
+
* @param opts TWooksHttpOptions
|
|
53
|
+
* @param wooks Wooks | WooksAdapterBase
|
|
54
|
+
* @returns WooksHttp
|
|
55
|
+
*/
|
|
50
56
|
export declare function createHttpApp(opts?: TWooksHttpOptions, wooks?: Wooks | WooksAdapterBase): WooksHttp;
|
|
51
57
|
|
|
52
58
|
export declare function createHttpContext(data: THttpEventData, options: TEventOptions): {
|
|
@@ -384,6 +390,10 @@ export declare function useCookies(): {
|
|
|
384
390
|
|
|
385
391
|
export declare function useHeaders(): IncomingHttpHeaders;
|
|
386
392
|
|
|
393
|
+
/**
|
|
394
|
+
* Wrapper on useEventContext with HTTP event types
|
|
395
|
+
* @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
|
|
396
|
+
*/
|
|
387
397
|
export declare function useHttpContext<T extends TEmpty>(): {
|
|
388
398
|
getCtx: () => THttpContextStore & T & TGenericContextStore<THttpEventData>;
|
|
389
399
|
restoreCtx: () => TGenericContextStore<TEmpty>;
|
|
@@ -498,15 +508,49 @@ export declare class WooksHttp extends WooksAdapterBase {
|
|
|
498
508
|
head<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): TProstoRouterPathHandle<ParamsType>;
|
|
499
509
|
options<ResType = unknown, ParamsType = Record<string, string | string[]>>(path: string, handler: TWooksHandler<ResType>): TProstoRouterPathHandle<ParamsType>;
|
|
500
510
|
protected server?: Server;
|
|
511
|
+
/**
|
|
512
|
+
* Starts the http(s) server.
|
|
513
|
+
*
|
|
514
|
+
* Use this only if you rely on Wooks server.
|
|
515
|
+
*/
|
|
501
516
|
listen(...args: Parameters<Server['listen']>): Promise<unknown>;
|
|
517
|
+
/**
|
|
518
|
+
* Stops the server if it was attached or passed via argument
|
|
519
|
+
* @param server
|
|
520
|
+
*/
|
|
502
521
|
close(server?: Server): Promise<unknown>;
|
|
522
|
+
/**
|
|
523
|
+
* Returns http(s) server that was attached to Wooks
|
|
524
|
+
*
|
|
525
|
+
* See attachServer method docs
|
|
526
|
+
* @returns Server
|
|
527
|
+
*/
|
|
503
528
|
getServer(): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse> | undefined;
|
|
529
|
+
/**
|
|
530
|
+
* Attaches http(s) server instance
|
|
531
|
+
* to Wooks.
|
|
532
|
+
*
|
|
533
|
+
* Use it only if you want to `close` method to stop the server.
|
|
534
|
+
* @param server Server
|
|
535
|
+
*/
|
|
504
536
|
attachServer(server?: Server): void;
|
|
505
537
|
protected responder: {
|
|
506
538
|
createResponse: <T = unknown>(data: T) => BaseHttpResponse<T | TWooksErrorBodyExt> | null;
|
|
507
539
|
respond: (data: unknown) => Promise<unknown> | undefined;
|
|
508
540
|
};
|
|
509
541
|
protected respond(data: unknown): void;
|
|
542
|
+
/**
|
|
543
|
+
* Returns server callback function
|
|
544
|
+
* that can be passed to any node server:
|
|
545
|
+
* ```js
|
|
546
|
+
* import { createHttpApp } from '@wooksjs/event-http'
|
|
547
|
+
* import http from 'http'
|
|
548
|
+
*
|
|
549
|
+
* const app = createHttpApp()
|
|
550
|
+
* const server = http.createServer(app.getServerCb())
|
|
551
|
+
* server.listen(3000)
|
|
552
|
+
* ```
|
|
553
|
+
*/
|
|
510
554
|
getServerCb(): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
511
555
|
protected processHandlers(handlers: TWooksHandler<unknown>[]): Promise<void>;
|
|
512
556
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -10,6 +10,10 @@ function createHttpContext(data, options) {
|
|
|
10
10
|
options,
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Wrapper on useEventContext with HTTP event types
|
|
15
|
+
* @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
|
|
16
|
+
*/
|
|
13
17
|
function useHttpContext() {
|
|
14
18
|
return useEventContext('HTTP');
|
|
15
19
|
}
|
|
@@ -830,7 +834,7 @@ class HttpErrorRenderer extends BaseHttpResponseRenderer {
|
|
|
830
834
|
`<head><title>${data.statusCode} ${httpStatusCodes[data.statusCode]}</title></head>` +
|
|
831
835
|
`<body><center><h1>${data.statusCode} ${httpStatusCodes[data.statusCode]}</h1></center>` +
|
|
832
836
|
`<center><h4>${data.message}</h1></center><hr color="#666">` +
|
|
833
|
-
`<center style="color: #666;"> Wooks v${"0.3.
|
|
837
|
+
`<center style="color: #666;"> Wooks v${"0.3.1"} </center>` +
|
|
834
838
|
`${keys.length
|
|
835
839
|
? `<pre style="${preStyles}">${JSON.stringify(Object.assign(Object.assign({}, data), { statusCode: undefined, message: undefined, error: undefined }), null, ' ')}</pre>`
|
|
836
840
|
: ''}` +
|
|
@@ -971,6 +975,11 @@ class WooksHttp extends WooksAdapterBase {
|
|
|
971
975
|
options(path, handler) {
|
|
972
976
|
return this.on('OPTIONS', path, handler);
|
|
973
977
|
}
|
|
978
|
+
/**
|
|
979
|
+
* Starts the http(s) server.
|
|
980
|
+
*
|
|
981
|
+
* Use this only if you rely on Wooks server.
|
|
982
|
+
*/
|
|
974
983
|
listen(...args) {
|
|
975
984
|
return __awaiter(this, void 0, void 0, function* () {
|
|
976
985
|
const server = (this.server = http.createServer(this.getServerCb()));
|
|
@@ -981,6 +990,10 @@ class WooksHttp extends WooksAdapterBase {
|
|
|
981
990
|
});
|
|
982
991
|
});
|
|
983
992
|
}
|
|
993
|
+
/**
|
|
994
|
+
* Stops the server if it was attached or passed via argument
|
|
995
|
+
* @param server
|
|
996
|
+
*/
|
|
984
997
|
close(server) {
|
|
985
998
|
const srv = server || this.server;
|
|
986
999
|
return new Promise((resolve, reject) => {
|
|
@@ -991,9 +1004,22 @@ class WooksHttp extends WooksAdapterBase {
|
|
|
991
1004
|
});
|
|
992
1005
|
});
|
|
993
1006
|
}
|
|
1007
|
+
/**
|
|
1008
|
+
* Returns http(s) server that was attached to Wooks
|
|
1009
|
+
*
|
|
1010
|
+
* See attachServer method docs
|
|
1011
|
+
* @returns Server
|
|
1012
|
+
*/
|
|
994
1013
|
getServer() {
|
|
995
1014
|
return this.server;
|
|
996
1015
|
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Attaches http(s) server instance
|
|
1018
|
+
* to Wooks.
|
|
1019
|
+
*
|
|
1020
|
+
* Use it only if you want to `close` method to stop the server.
|
|
1021
|
+
* @param server Server
|
|
1022
|
+
*/
|
|
997
1023
|
attachServer(server) {
|
|
998
1024
|
this.server = server;
|
|
999
1025
|
}
|
|
@@ -1003,6 +1029,18 @@ class WooksHttp extends WooksAdapterBase {
|
|
|
1003
1029
|
this.logger.error('Uncought response exception', e);
|
|
1004
1030
|
}));
|
|
1005
1031
|
}
|
|
1032
|
+
/**
|
|
1033
|
+
* Returns server callback function
|
|
1034
|
+
* that can be passed to any node server:
|
|
1035
|
+
* ```js
|
|
1036
|
+
* import { createHttpApp } from '@wooksjs/event-http'
|
|
1037
|
+
* import http from 'http'
|
|
1038
|
+
*
|
|
1039
|
+
* const app = createHttpApp()
|
|
1040
|
+
* const server = http.createServer(app.getServerCb())
|
|
1041
|
+
* server.listen(3000)
|
|
1042
|
+
* ```
|
|
1043
|
+
*/
|
|
1006
1044
|
getServerCb() {
|
|
1007
1045
|
return (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
1008
1046
|
var _a, _b, _c;
|
|
@@ -1056,6 +1094,12 @@ class WooksHttp extends WooksAdapterBase {
|
|
|
1056
1094
|
});
|
|
1057
1095
|
}
|
|
1058
1096
|
}
|
|
1097
|
+
/**
|
|
1098
|
+
* Factory for WooksHttp App
|
|
1099
|
+
* @param opts TWooksHttpOptions
|
|
1100
|
+
* @param wooks Wooks | WooksAdapterBase
|
|
1101
|
+
* @returns WooksHttp
|
|
1102
|
+
*/
|
|
1059
1103
|
function createHttpApp(opts, wooks) {
|
|
1060
1104
|
return new WooksHttp(opts, wooks);
|
|
1061
1105
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/event-http",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "@wooksjs/event-http",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"url": "https://github.com/wooksjs/wooksjs/issues"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"wooks": "0.3.
|
|
34
|
+
"wooks": "0.3.1",
|
|
35
35
|
"@prostojs/router": "^0.1.0",
|
|
36
|
-
"@wooksjs/event-core": "0.3.
|
|
36
|
+
"@wooksjs/event-core": "0.3.1"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@prostojs/logger": "^0.3.6"
|