@fc3/server 0.1.2 → 0.1.3
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/.last-compile-time +1 -1
- package/dist/.last-publish-time +1 -1
- package/dist/src/http-server/endpoint/ping.d.ts +12 -0
- package/dist/src/http-server/endpoint/ping.js +22 -0
- package/dist/src/http-server/endpoint/ping.js.map +1 -0
- package/dist/src/http-server/endpoint.d.ts +47 -0
- package/dist/src/http-server/endpoint.js +216 -0
- package/dist/src/http-server/endpoint.js.map +1 -0
- package/dist/src/http-server/interface/endpoint-constructor.d.ts +5 -0
- package/dist/src/http-server/interface/endpoint-constructor.js +4 -0
- package/dist/src/http-server/interface/endpoint-constructor.js.map +1 -0
- package/dist/src/http-server/interface/result-serializer.d.ts +4 -0
- package/dist/src/http-server/interface/result-serializer.js +3 -0
- package/dist/src/http-server/interface/result-serializer.js.map +1 -0
- package/dist/src/http-server/middleware.d.ts +6 -0
- package/dist/src/http-server/middleware.js +9 -0
- package/dist/src/http-server/middleware.js.map +1 -0
- package/dist/src/http-server/result-serializer/html.d.ts +16 -0
- package/dist/src/http-server/result-serializer/html.js +74 -0
- package/dist/src/http-server/result-serializer/html.js.map +1 -0
- package/dist/src/http-server/result-serializer/json.d.ts +8 -0
- package/dist/src/http-server/result-serializer/json.js +17 -0
- package/dist/src/http-server/result-serializer/json.js.map +1 -0
- package/dist/src/http-server/route.d.ts +21 -0
- package/dist/src/http-server/route.js +73 -0
- package/dist/src/http-server/route.js.map +1 -0
- package/dist/src/http-server/router.d.ts +20 -0
- package/dist/src/http-server/router.js +78 -0
- package/dist/src/http-server/router.js.map +1 -0
- package/dist/src/http-server/type/session-resolver.d.ts +6 -0
- package/dist/src/http-server/type/session-resolver.js +3 -0
- package/dist/src/http-server/type/session-resolver.js.map +1 -0
- package/dist/src/http-server/utility/create-server.d.ts +10 -0
- package/dist/src/http-server/utility/create-server.js +24 -0
- package/dist/src/http-server/utility/create-server.js.map +1 -0
- package/dist/src/http-server/utility/path-parser.d.ts +11 -0
- package/dist/src/http-server/utility/path-parser.js +34 -0
- package/dist/src/http-server/utility/path-parser.js.map +1 -0
- package/dist/src/http-server/utility/standardize-html-indentation.d.ts +2 -0
- package/dist/src/http-server/utility/standardize-html-indentation.js +44 -0
- package/dist/src/http-server/utility/standardize-html-indentation.js.map +1 -0
- package/dist/src/http-server/websocket-wrapper.d.ts +21 -0
- package/dist/src/http-server/websocket-wrapper.js +56 -0
- package/dist/src/http-server/websocket-wrapper.js.map +1 -0
- package/dist/src/http-server.d.ts +40 -0
- package/dist/src/http-server.js +209 -0
- package/dist/src/http-server.js.map +1 -0
- package/dist/src/index.d.ts +5 -5
- package/dist/src/index.js +6 -6
- package/dist/src/index.js.map +1 -1
- package/dist/src/tcp-server.d.ts +13 -0
- package/dist/src/tcp-server.js +41 -0
- package/dist/src/tcp-server.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const http_1 = require("@fc3/http");
|
|
7
|
+
const middleware_1 = __importDefault(require("./middleware.js"));
|
|
8
|
+
class Router extends middleware_1.default {
|
|
9
|
+
constructor(logger, endpoint_setup_callback) {
|
|
10
|
+
super();
|
|
11
|
+
this.logger = logger;
|
|
12
|
+
this.endpoint_setup_callback = endpoint_setup_callback;
|
|
13
|
+
this.method_routes = {
|
|
14
|
+
[http_1.HttpMethod.DELETE]: [],
|
|
15
|
+
[http_1.HttpMethod.GET]: [],
|
|
16
|
+
[http_1.HttpMethod.HEAD]: [],
|
|
17
|
+
[http_1.HttpMethod.OPTIONS]: [],
|
|
18
|
+
[http_1.HttpMethod.PATCH]: [],
|
|
19
|
+
[http_1.HttpMethod.PUT]: [],
|
|
20
|
+
[http_1.HttpMethod.POST]: []
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
addRoute(route) {
|
|
24
|
+
const method = route.getMethod();
|
|
25
|
+
const routes = this.getRoutesForMethod(method);
|
|
26
|
+
routes.push(route);
|
|
27
|
+
}
|
|
28
|
+
// Returns a boolean indicating whether the request was successfully processed
|
|
29
|
+
// (read: we can skip subsequent middleware)
|
|
30
|
+
async handleRequest(request, response) {
|
|
31
|
+
const method = request.getMethod();
|
|
32
|
+
const routes = this.getRoutesForMethod(method);
|
|
33
|
+
const logger = this.getLogger();
|
|
34
|
+
if (routes.length === 0) {
|
|
35
|
+
logger.warn(`No routes matched method: ${method}`);
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const path = request.getPath();
|
|
39
|
+
const routes_subset = routes.filter((route) => {
|
|
40
|
+
return route.matchesPath(path);
|
|
41
|
+
});
|
|
42
|
+
if (routes_subset.length === 0) {
|
|
43
|
+
logger.warn(`No routes matched path: ${path}`);
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const content_types = request.getAcceptedContentTypes();
|
|
47
|
+
const matching_route = routes_subset.find((route) => {
|
|
48
|
+
return route.matchesContentTypes(content_types);
|
|
49
|
+
});
|
|
50
|
+
if (matching_route === undefined) {
|
|
51
|
+
logger.warn(`No routes matched content types: ${content_types}`);
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
// TODO: Why is this necessary, given that we're explicitly checking for
|
|
55
|
+
// undefined values above?
|
|
56
|
+
const route = matching_route;
|
|
57
|
+
const path_parameters = route.getPathParametersForRequest(request);
|
|
58
|
+
request.setPathParameters(path_parameters);
|
|
59
|
+
const endpoint = await route.buildEndpoint(request, response);
|
|
60
|
+
if (this.endpoint_setup_callback !== undefined) {
|
|
61
|
+
await this.endpoint_setup_callback(endpoint);
|
|
62
|
+
}
|
|
63
|
+
await endpoint.serve();
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
getRoutesForMethod(method) {
|
|
67
|
+
const method_routes = this.getMethodRoutes();
|
|
68
|
+
return method_routes[method];
|
|
69
|
+
}
|
|
70
|
+
getMethodRoutes() {
|
|
71
|
+
return this.method_routes;
|
|
72
|
+
}
|
|
73
|
+
getLogger() {
|
|
74
|
+
return this.logger;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.default = Router;
|
|
78
|
+
//# sourceMappingURL=router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../../src/http-server/router.ts"],"names":[],"mappings":";;;;;AACA,oCAAwE;AAExE,wEAAgD;AAkBhD,MAAM,MAAO,SAAQ,oBAAU;IAK9B,YAAmB,MAAc,EAAE,uBAA+C;QACjF,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,uBAAuB,GAAG,uBAAuB,CAAC;QAEvD,IAAI,CAAC,aAAa,GAAG;YACpB,CAAC,iBAAU,CAAC,MAAM,CAAC,EAAE,EAAE;YACvB,CAAC,iBAAU,CAAC,GAAG,CAAC,EAAE,EAAE;YACpB,CAAC,iBAAU,CAAC,IAAI,CAAC,EAAE,EAAE;YACrB,CAAC,iBAAU,CAAC,OAAO,CAAC,EAAE,EAAE;YACxB,CAAC,iBAAU,CAAC,KAAK,CAAC,EAAE,EAAE;YACtB,CAAC,iBAAU,CAAC,GAAG,CAAC,EAAE,EAAE;YACpB,CAAC,iBAAU,CAAC,IAAI,CAAC,EAAE,EAAE;SACrB,CAAC;IACH,CAAC;IAEM,QAAQ,CAAC,KAAY;QAC3B,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;QACjC,MAAM,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAE/C,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,8EAA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,CAAC,CAAC;QAEnE,OAAO,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAAC;QAE3C,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,aAAa,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAE9D,IAAI,IAAI,CAAC,uBAAuB,KAAK,SAAS,EAAE,CAAC;YAChD,MAAM,IAAI,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC;QAC9C,CAAC;QAED,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC;QAEvB,OAAO,IAAI,CAAC;IACb,CAAC;IAEO,kBAAkB,CAAC,MAAkB;QAC5C,MAAM,aAAa,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QAE7C,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;IAEO,eAAe;QACtB,OAAO,IAAI,CAAC,aAAa,CAAC;IAC3B,CAAC;IAEO,SAAS;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;CACD;AAED,kBAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-resolver.js","sourceRoot":"","sources":["../../../../src/http-server/type/session-resolver.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Server as HttpServer } from './../../http';
|
|
2
|
+
import { Server as HttpsServer } from 'https';
|
|
3
|
+
import { NetworkProtocol } from '@fc3/network';
|
|
4
|
+
interface ServerConfig {
|
|
5
|
+
readonly key: string | Buffer | undefined;
|
|
6
|
+
readonly cert: string | Buffer | undefined;
|
|
7
|
+
readonly protocol: NetworkProtocol;
|
|
8
|
+
}
|
|
9
|
+
declare function createServer(config: ServerConfig): HttpServer | HttpsServer;
|
|
10
|
+
export default createServer;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const http_1 = require("./../../http.js");
|
|
4
|
+
const https_1 = require("https");
|
|
5
|
+
const errors_1 = require("@fc3/errors");
|
|
6
|
+
const network_1 = require("@fc3/network");
|
|
7
|
+
function createServer(config) {
|
|
8
|
+
const { key, cert, protocol } = config;
|
|
9
|
+
if (protocol === network_1.NetworkProtocol.HTTPS) {
|
|
10
|
+
if (key === undefined || cert === undefined) {
|
|
11
|
+
throw new errors_1.InvalidError('Must specify a key and cert when using HTTPS');
|
|
12
|
+
}
|
|
13
|
+
return (0, https_1.createServer)({
|
|
14
|
+
key,
|
|
15
|
+
cert
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
if (key !== undefined || cert !== undefined) {
|
|
19
|
+
throw new errors_1.InvalidError('SSL key/cert were supplied, but protocol was HTTP');
|
|
20
|
+
}
|
|
21
|
+
return (0, http_1.createServer)();
|
|
22
|
+
}
|
|
23
|
+
exports.default = createServer;
|
|
24
|
+
//# sourceMappingURL=create-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-server.js","sourceRoot":"","sources":["../../../../src/http-server/utility/create-server.ts"],"names":[],"mappings":";;AAAA,+BAA4E;AAC5E,iCAA+E;AAE/E,wCAAyC;AACzC,0CAA6C;AAQ7C,SAAS,YAAY,CAAC,MAAoB;IACzC,MAAM,EAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAC,GAAG,MAAM,CAAC;IAErC,IAAI,QAAQ,KAAK,yBAAe,CAAC,KAAK,EAAE,CAAC;QACxC,IAAI,GAAG,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YAC7C,MAAM,IAAI,qBAAY,CAAC,8CAA8C,CAAC,CAAC;QACxE,CAAC;QAED,OAAO,IAAA,oBAAiB,EAAC;YACxB,GAAG;YACH,IAAI;SACJ,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,GAAG,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QAC7C,MAAM,IAAI,qBAAY,CAAC,mDAAmD,CAAC,CAAC;IAC7E,CAAC;IAED,OAAO,IAAA,mBAAgB,GAAE,CAAC;AAC3B,CAAC;AAED,kBAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface ParsedPath {
|
|
2
|
+
readonly regex: RegExp;
|
|
3
|
+
readonly parameter_keys: string[];
|
|
4
|
+
}
|
|
5
|
+
declare class PathParser {
|
|
6
|
+
private path;
|
|
7
|
+
constructor(path: string);
|
|
8
|
+
parse(): ParsedPath;
|
|
9
|
+
private getPathWithoutLeadingSlash;
|
|
10
|
+
}
|
|
11
|
+
export default PathParser;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class PathParser {
|
|
4
|
+
constructor(path) {
|
|
5
|
+
this.path = path;
|
|
6
|
+
}
|
|
7
|
+
parse() {
|
|
8
|
+
const path = this.getPathWithoutLeadingSlash();
|
|
9
|
+
const path_parts = path.split('/');
|
|
10
|
+
const parameter_keys = [];
|
|
11
|
+
const regex_parts = path_parts.map((path_part) => {
|
|
12
|
+
const colon_index = path_part.indexOf(':');
|
|
13
|
+
if (colon_index === -1) {
|
|
14
|
+
return path_part;
|
|
15
|
+
}
|
|
16
|
+
const prefix = path_part.slice(0, colon_index);
|
|
17
|
+
const parameter_key = path_part.slice(colon_index + 1);
|
|
18
|
+
parameter_keys.push(parameter_key);
|
|
19
|
+
return `${prefix}([^\\/?]+)`;
|
|
20
|
+
});
|
|
21
|
+
const querystring = '(\\?[^/?]+)?';
|
|
22
|
+
const regex_string = '^/' + regex_parts.join('/') + querystring + '$';
|
|
23
|
+
const regex = new RegExp(regex_string);
|
|
24
|
+
return {
|
|
25
|
+
regex,
|
|
26
|
+
parameter_keys
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
getPathWithoutLeadingSlash() {
|
|
30
|
+
return this.path.slice(1);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.default = PathParser;
|
|
34
|
+
//# sourceMappingURL=path-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-parser.js","sourceRoot":"","sources":["../../../../src/http-server/utility/path-parser.ts"],"names":[],"mappings":";;AAKA,MAAM,UAAU;IAGf,YAAmB,IAAY;QAC9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;IAEM,KAAK;QACX,MAAM,IAAI,GAAG,IAAI,CAAC,0BAA0B,EAAE,CAAC;QAC/C,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnC,MAAM,cAAc,GAAa,EAAE,CAAC;QAEpC,MAAM,WAAW,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;YAChD,MAAM,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YAE3C,IAAI,WAAW,KAAK,CAAC,CAAC,EAAE,CAAC;gBACxB,OAAO,SAAS,CAAC;YAClB,CAAC;YAED,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;YAC/C,MAAM,aAAa,GAAG,SAAS,CAAC,KAAK,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC;YAEvD,cAAc,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YAEnC,OAAO,GAAG,MAAM,YAAY,CAAC;QAC9B,CAAC,CAAC,CAAC;QAEH,MAAM,WAAW,GAAG,cAAc,CAAC;QAEnC,MAAM,YAAY,GAAG,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,WAAW,GAAG,GAAG,CAAC;QACtE,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,YAAY,CAAC,CAAC;QAEvC,OAAO;YACN,KAAK;YACL,cAAc;SACd,CAAC;IACH,CAAC;IAEO,0BAA0B;QACjC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC3B,CAAC;CACD;AAED,kBAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function standardizeHtmlIndentation(html) {
|
|
4
|
+
const original_lines = html.split('\n');
|
|
5
|
+
const standardized_lines = [];
|
|
6
|
+
let indentation = '';
|
|
7
|
+
let within_multiline_block = false;
|
|
8
|
+
original_lines.forEach((original_line) => {
|
|
9
|
+
const trimmed_line = original_line.trim();
|
|
10
|
+
if (trimmed_line.length === 0) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (trimmed_line === '<br>' || trimmed_line === '<hr>') {
|
|
14
|
+
throw new Error('Specify void elements as self-closing');
|
|
15
|
+
}
|
|
16
|
+
const has_open_tag = /^<[a-z]/.test(trimmed_line);
|
|
17
|
+
const has_close_tag = /<\/[^>]+>$/.test(trimmed_line);
|
|
18
|
+
const is_self_closing = /^<[a-z].*\/>$/.test(trimmed_line);
|
|
19
|
+
if (!has_open_tag && has_close_tag && !is_self_closing) {
|
|
20
|
+
indentation = indentation.slice(0, -1);
|
|
21
|
+
}
|
|
22
|
+
if (within_multiline_block) {
|
|
23
|
+
standardized_lines.push(original_line);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
const indented_line = `${indentation}${trimmed_line}`;
|
|
27
|
+
standardized_lines.push(indented_line);
|
|
28
|
+
}
|
|
29
|
+
const multiline_open_regex = /<(pre|textarea|script)/;
|
|
30
|
+
const multiline_close_regex = /<\/(pre|textarea|script)>/;
|
|
31
|
+
if (has_open_tag && multiline_open_regex.test(trimmed_line)) {
|
|
32
|
+
within_multiline_block = true;
|
|
33
|
+
}
|
|
34
|
+
if (has_close_tag && multiline_close_regex.test(trimmed_line) && within_multiline_block) {
|
|
35
|
+
within_multiline_block = false;
|
|
36
|
+
}
|
|
37
|
+
if (has_open_tag && !has_close_tag && !is_self_closing) {
|
|
38
|
+
indentation += '\t';
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return standardized_lines.join('\n');
|
|
42
|
+
}
|
|
43
|
+
exports.default = standardizeHtmlIndentation;
|
|
44
|
+
//# sourceMappingURL=standardize-html-indentation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standardize-html-indentation.js","sourceRoot":"","sources":["../../../../src/http-server/utility/standardize-html-indentation.ts"],"names":[],"mappings":";;AAAA,SAAS,0BAA0B,CAAC,IAAY;IAC/C,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACxC,MAAM,kBAAkB,GAAa,EAAE,CAAC;IAExC,IAAI,WAAW,GAAG,EAAE,CAAC;IACrB,IAAI,sBAAsB,GAAG,KAAK,CAAC;IAEnC,cAAc,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,EAAE;QACxC,MAAM,YAAY,GAAG,aAAa,CAAC,IAAI,EAAE,CAAC;QAE1C,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC/B,OAAO;QACR,CAAC;QAED,IAAI,YAAY,KAAK,MAAM,IAAI,YAAY,KAAK,MAAM,EAAE,CAAC;YACxD,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC1D,CAAC;QAED,MAAM,YAAY,GAAG,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAClD,MAAM,aAAa,GAAG,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACtD,MAAM,eAAe,GAAG,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAE3D,IAAI,CAAC,YAAY,IAAI,aAAa,IAAI,CAAC,eAAe,EAAE,CAAC;YACxD,WAAW,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACxC,CAAC;QAED,IAAI,sBAAsB,EAAE,CAAC;YAC5B,kBAAkB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACxC,CAAC;aAAM,CAAC;YACP,MAAM,aAAa,GAAG,GAAG,WAAW,GAAG,YAAY,EAAE,CAAC;YAEtD,kBAAkB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACxC,CAAC;QAED,MAAM,oBAAoB,GAAG,wBAAwB,CAAC;QACtD,MAAM,qBAAqB,GAAG,2BAA2B,CAAC;QAE1D,IAAI,YAAY,IAAI,oBAAoB,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;YAC7D,sBAAsB,GAAG,IAAI,CAAC;QAC/B,CAAC;QAED,IAAI,aAAa,IAAI,qBAAqB,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,sBAAsB,EAAE,CAAC;YACzF,sBAAsB,GAAG,KAAK,CAAC;QAChC,CAAC;QAED,IAAI,YAAY,IAAI,CAAC,aAAa,IAAI,CAAC,eAAe,EAAE,CAAC;YACxD,WAAW,IAAI,IAAI,CAAC;QACrB,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,OAAO,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC;AAED,kBAAe,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import WebSocket from 'ws';
|
|
3
|
+
import { Socket, SocketOptions } from '@fc3/network';
|
|
4
|
+
declare class WebsocketWrapper extends EventEmitter implements Socket {
|
|
5
|
+
connecting: boolean;
|
|
6
|
+
pending: boolean;
|
|
7
|
+
readyState: 'open';
|
|
8
|
+
private websocket;
|
|
9
|
+
constructor(websocket: WebSocket);
|
|
10
|
+
write(message: string): void;
|
|
11
|
+
end(): void;
|
|
12
|
+
destroy(): void;
|
|
13
|
+
connect(_options: SocketOptions): void;
|
|
14
|
+
private bindHandlers;
|
|
15
|
+
private assignHandlers;
|
|
16
|
+
private handleMessage;
|
|
17
|
+
private handleClose;
|
|
18
|
+
private handleError;
|
|
19
|
+
private getWebsocket;
|
|
20
|
+
}
|
|
21
|
+
export default WebsocketWrapper;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const events_1 = require("events");
|
|
4
|
+
class WebsocketWrapper extends events_1.EventEmitter {
|
|
5
|
+
constructor(websocket) {
|
|
6
|
+
super();
|
|
7
|
+
this.connecting = false;
|
|
8
|
+
this.pending = false;
|
|
9
|
+
this.readyState = 'open';
|
|
10
|
+
this.websocket = websocket;
|
|
11
|
+
this.bindHandlers();
|
|
12
|
+
this.assignHandlers();
|
|
13
|
+
}
|
|
14
|
+
write(message) {
|
|
15
|
+
const websocket = this.getWebsocket();
|
|
16
|
+
websocket.send(message);
|
|
17
|
+
}
|
|
18
|
+
end() {
|
|
19
|
+
const websocket = this.getWebsocket();
|
|
20
|
+
websocket.close();
|
|
21
|
+
}
|
|
22
|
+
destroy() {
|
|
23
|
+
const websocket = this.getWebsocket();
|
|
24
|
+
websocket.terminate();
|
|
25
|
+
}
|
|
26
|
+
connect(_options) {
|
|
27
|
+
throw new Error('Cannot call connect() on a server-side websocket');
|
|
28
|
+
}
|
|
29
|
+
bindHandlers() {
|
|
30
|
+
this.handleMessage = this.handleMessage.bind(this);
|
|
31
|
+
this.handleClose = this.handleClose.bind(this);
|
|
32
|
+
this.handleError = this.handleError.bind(this);
|
|
33
|
+
}
|
|
34
|
+
assignHandlers() {
|
|
35
|
+
const websocket = this.getWebsocket();
|
|
36
|
+
websocket.on('message', this.handleMessage);
|
|
37
|
+
websocket.on('close', this.handleClose);
|
|
38
|
+
websocket.on('error', this.handleError);
|
|
39
|
+
}
|
|
40
|
+
handleMessage(message) {
|
|
41
|
+
this.emit('data', message);
|
|
42
|
+
}
|
|
43
|
+
handleClose() {
|
|
44
|
+
// Simulate the normal events in a native Net.Socket teardown lifecycle:
|
|
45
|
+
this.emit('end');
|
|
46
|
+
this.emit('close');
|
|
47
|
+
}
|
|
48
|
+
handleError(error) {
|
|
49
|
+
this.emit('error', error);
|
|
50
|
+
}
|
|
51
|
+
getWebsocket() {
|
|
52
|
+
return this.websocket;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.default = WebsocketWrapper;
|
|
56
|
+
//# sourceMappingURL=websocket-wrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket-wrapper.js","sourceRoot":"","sources":["../../../src/http-server/websocket-wrapper.ts"],"names":[],"mappings":";;AAAA,mCAAoC;AAMpC,MAAM,gBAAiB,SAAQ,qBAAY;IAQ1C,YAAmB,SAAoB;QACtC,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC;QAEzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAE3B,IAAI,CAAC,YAAY,EAAE,CAAC;QACpB,IAAI,CAAC,cAAc,EAAE,CAAC;IACvB,CAAC;IAEM,KAAK,CAAC,OAAe;QAC3B,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAEtC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IAEM,GAAG;QACT,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAEtC,SAAS,CAAC,KAAK,EAAE,CAAC;IACnB,CAAC;IAEM,OAAO;QACb,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAEtC,SAAS,CAAC,SAAS,EAAE,CAAC;IACvB,CAAC;IAEM,OAAO,CAAC,QAAuB;QACrC,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACrE,CAAC;IAEO,YAAY;QACnB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IAEO,cAAc;QACrB,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAEtC,SAAS,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAC5C,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QACxC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC;IAEO,aAAa,CAAC,OAAe;QACpC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5B,CAAC;IAEO,WAAW;QAClB,wEAAwE;QACxE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACjB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACpB,CAAC;IAEO,WAAW,CAAC,KAAY;QAC/B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC3B,CAAC;IAEO,YAAY;QACnB,OAAO,IAAI,CAAC,SAAS,CAAC;IACvB,CAAC;CACD;AAED,kBAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import HTTP from './http';
|
|
2
|
+
import HTTPS from 'https';
|
|
3
|
+
import { NetworkProtocol } from '@fc3/network';
|
|
4
|
+
import BaseServer from './base';
|
|
5
|
+
import Middleware from './http-server/middleware';
|
|
6
|
+
import Endpoint from './http-server/endpoint';
|
|
7
|
+
import ServerOptions from './type/server-options';
|
|
8
|
+
import SessionResolver from './http-server/type/session-resolver';
|
|
9
|
+
import EndpointConstructor from './http-server/interface/endpoint-constructor';
|
|
10
|
+
declare class HttpServer extends BaseServer {
|
|
11
|
+
private router;
|
|
12
|
+
private middlewares;
|
|
13
|
+
private connections;
|
|
14
|
+
private session_resolver;
|
|
15
|
+
private websocket_server;
|
|
16
|
+
constructor(options: ServerOptions, raw_server?: HTTP.Server | HTTPS.Server);
|
|
17
|
+
stop(): Promise<void>;
|
|
18
|
+
addEndpoint(endpoint_constructor: EndpointConstructor): this;
|
|
19
|
+
prependMiddleware(middleware: Middleware): this;
|
|
20
|
+
appendMiddleware(middleware: Middleware): this;
|
|
21
|
+
enablePingEndpoint(): this;
|
|
22
|
+
setSessionResolver(session_resolver: SessionResolver): void;
|
|
23
|
+
protected bindHandlers(): void;
|
|
24
|
+
protected getProtocol(): NetworkProtocol;
|
|
25
|
+
protected setupEndpoint(endpoint: Endpoint<any, any>): Promise<void>;
|
|
26
|
+
private handleRawRequest;
|
|
27
|
+
private handleRequestAsync;
|
|
28
|
+
private handleUpgrade;
|
|
29
|
+
private handleUpgradeAsync;
|
|
30
|
+
private assignSessionToRequest;
|
|
31
|
+
private drain;
|
|
32
|
+
private getRouter;
|
|
33
|
+
private getMiddlewares;
|
|
34
|
+
private getWebsocketServer;
|
|
35
|
+
private hasSessionResolver;
|
|
36
|
+
private getSessionResolver;
|
|
37
|
+
private addConnection;
|
|
38
|
+
private getConnections;
|
|
39
|
+
}
|
|
40
|
+
export default HttpServer;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const http_1 = __importDefault(require("./http.js"));
|
|
7
|
+
const util_1 = __importDefault(require("util"));
|
|
8
|
+
const https_1 = __importDefault(require("https"));
|
|
9
|
+
const ws_1 = __importDefault(require("ws"));
|
|
10
|
+
const time_1 = require("@fc3/time");
|
|
11
|
+
const errors_1 = require("@fc3/errors");
|
|
12
|
+
const http_2 = require("@fc3/http");
|
|
13
|
+
const network_1 = require("@fc3/network");
|
|
14
|
+
const execution_context_1 = __importDefault(require("@fc3/execution-context"));
|
|
15
|
+
const tcp_1 = require("@fc3/tcp");
|
|
16
|
+
const route_1 = __importDefault(require("./http-server/route.js"));
|
|
17
|
+
const router_1 = __importDefault(require("./http-server/router.js"));
|
|
18
|
+
const base_1 = __importDefault(require("./base.js"));
|
|
19
|
+
const server_event_1 = __importDefault(require("./enum/server-event.js"));
|
|
20
|
+
const ping_1 = __importDefault(require("./http-server/endpoint/ping.js"));
|
|
21
|
+
const websocket_wrapper_1 = __importDefault(require("./http-server/websocket-wrapper.js"));
|
|
22
|
+
class HttpServer extends base_1.default {
|
|
23
|
+
constructor(options, raw_server) {
|
|
24
|
+
if (raw_server === undefined) {
|
|
25
|
+
raw_server = http_1.default.createServer();
|
|
26
|
+
}
|
|
27
|
+
super(options, raw_server);
|
|
28
|
+
const logger = this.getLogger();
|
|
29
|
+
const router = new router_1.default(logger, (endpoint) => {
|
|
30
|
+
return this.setupEndpoint(endpoint);
|
|
31
|
+
});
|
|
32
|
+
this.router = router;
|
|
33
|
+
this.middlewares = [router];
|
|
34
|
+
this.connections = [];
|
|
35
|
+
}
|
|
36
|
+
async stop() {
|
|
37
|
+
await super.stop();
|
|
38
|
+
await this.drain();
|
|
39
|
+
}
|
|
40
|
+
addEndpoint(endpoint_constructor) {
|
|
41
|
+
const router = this.getRouter();
|
|
42
|
+
const route = new route_1.default(endpoint_constructor);
|
|
43
|
+
router.addRoute(route);
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
prependMiddleware(middleware) {
|
|
47
|
+
const middlewares = this.getMiddlewares();
|
|
48
|
+
middlewares.unshift(middleware);
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
appendMiddleware(middleware) {
|
|
52
|
+
const middlewares = this.getMiddlewares();
|
|
53
|
+
middlewares.push(middleware);
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
enablePingEndpoint() {
|
|
57
|
+
this.addEndpoint(ping_1.default);
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
setSessionResolver(session_resolver) {
|
|
61
|
+
this.session_resolver = session_resolver;
|
|
62
|
+
}
|
|
63
|
+
bindHandlers() {
|
|
64
|
+
const raw_server = this.getRawServer();
|
|
65
|
+
raw_server.on('request', this.handleRawRequest.bind(this));
|
|
66
|
+
raw_server.on('upgrade', this.handleUpgrade.bind(this));
|
|
67
|
+
}
|
|
68
|
+
getProtocol() {
|
|
69
|
+
const raw_server = this.getRawServer();
|
|
70
|
+
if (raw_server instanceof https_1.default.Server) {
|
|
71
|
+
return network_1.NetworkProtocol.HTTPS;
|
|
72
|
+
}
|
|
73
|
+
else if (raw_server instanceof http_1.default.Server) {
|
|
74
|
+
return network_1.NetworkProtocol.HTTP;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
throw new Error('Unable to determine server protocol');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async setupEndpoint(endpoint) {
|
|
81
|
+
}
|
|
82
|
+
handleRawRequest(raw_request, raw_response) {
|
|
83
|
+
const config = this.getConfig();
|
|
84
|
+
const execution_context = new execution_context_1.default(config);
|
|
85
|
+
const request = new http_2.IncomingRequest(raw_request, execution_context);
|
|
86
|
+
const response = new http_2.OutgoingResponse(raw_response);
|
|
87
|
+
response.setExecutionContext(execution_context);
|
|
88
|
+
response.setPath(request.getPath());
|
|
89
|
+
response.setMethod(request.getMethod());
|
|
90
|
+
const promise = this.handleRequestAsync(request, response);
|
|
91
|
+
promise.catch((error) => {
|
|
92
|
+
response.error(error);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
async handleRequestAsync(request, response) {
|
|
96
|
+
await this.assignSessionToRequest(request);
|
|
97
|
+
const middlewares = this.getMiddlewares();
|
|
98
|
+
const logger = this.getLogger();
|
|
99
|
+
let index = 0;
|
|
100
|
+
let error = undefined;
|
|
101
|
+
while (index < middlewares.length) {
|
|
102
|
+
const middleware = middlewares[index];
|
|
103
|
+
if (error) {
|
|
104
|
+
if (await middleware.handleError(error, request, response)) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
try {
|
|
110
|
+
if (await middleware.handleRequest(request, response)) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch (middleware_error) {
|
|
115
|
+
error = middleware_error;
|
|
116
|
+
logger.error(error);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
index++;
|
|
120
|
+
}
|
|
121
|
+
if (error === undefined) {
|
|
122
|
+
error = new errors_1.NotFoundError('Unable to find a matching resource for this request');
|
|
123
|
+
}
|
|
124
|
+
response.error(error);
|
|
125
|
+
}
|
|
126
|
+
handleUpgrade(raw_request, socket, head) {
|
|
127
|
+
const promise = this.handleUpgradeAsync(raw_request, socket, head);
|
|
128
|
+
promise.catch((error) => {
|
|
129
|
+
const logger = this.getLogger();
|
|
130
|
+
logger.error(`
|
|
131
|
+
Error occurred when upgrading websocket connection:
|
|
132
|
+
${error.message}
|
|
133
|
+
`);
|
|
134
|
+
socket.end();
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
async handleUpgradeAsync(raw_request, socket, head) {
|
|
138
|
+
const config = this.getConfig();
|
|
139
|
+
const execution_context = new execution_context_1.default(config);
|
|
140
|
+
const request = new http_2.IncomingRequest(raw_request, execution_context);
|
|
141
|
+
await this.assignSessionToRequest(request);
|
|
142
|
+
const websocket_server = this.getWebsocketServer();
|
|
143
|
+
websocket_server.handleUpgrade(raw_request, socket, head, (websocket) => {
|
|
144
|
+
const wrapper = new websocket_wrapper_1.default(websocket);
|
|
145
|
+
const connection = new tcp_1.IncomingConnection(wrapper, execution_context);
|
|
146
|
+
this.addConnection(connection);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
async assignSessionToRequest(request) {
|
|
150
|
+
if (!this.hasSessionResolver()) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const resolver = this.getSessionResolver();
|
|
154
|
+
const session = await resolver(request);
|
|
155
|
+
const execution_context = request.getExecutionContext();
|
|
156
|
+
if (session) {
|
|
157
|
+
execution_context.setSession(session);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async drain() {
|
|
161
|
+
const connections = this.getConnections();
|
|
162
|
+
connections.forEach((connection) => {
|
|
163
|
+
connection.end();
|
|
164
|
+
});
|
|
165
|
+
const raw_server = this.getRawServer();
|
|
166
|
+
const bound_method = raw_server.getConnections.bind(raw_server);
|
|
167
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
168
|
+
const getRawConnections = util_1.default.promisify(bound_method);
|
|
169
|
+
let raw_connection_count = await getRawConnections();
|
|
170
|
+
while (raw_connection_count > 0) {
|
|
171
|
+
await (0, time_1.sleep)(time_1.TimeInterval.ONE_SECOND);
|
|
172
|
+
raw_connection_count = await getRawConnections();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
getRouter() {
|
|
176
|
+
return this.router;
|
|
177
|
+
}
|
|
178
|
+
getMiddlewares() {
|
|
179
|
+
return this.middlewares;
|
|
180
|
+
}
|
|
181
|
+
getWebsocketServer() {
|
|
182
|
+
if (this.websocket_server === undefined) {
|
|
183
|
+
this.websocket_server = new ws_1.default.Server({
|
|
184
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
185
|
+
noServer: true
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
return this.websocket_server;
|
|
189
|
+
}
|
|
190
|
+
hasSessionResolver() {
|
|
191
|
+
return this.session_resolver !== undefined;
|
|
192
|
+
}
|
|
193
|
+
getSessionResolver() {
|
|
194
|
+
if (this.session_resolver === undefined) {
|
|
195
|
+
throw new Error('Tried to read session resolver, but it was not set');
|
|
196
|
+
}
|
|
197
|
+
return this.session_resolver;
|
|
198
|
+
}
|
|
199
|
+
addConnection(connection) {
|
|
200
|
+
const connections = this.getConnections();
|
|
201
|
+
connections.push(connection);
|
|
202
|
+
this.emit(server_event_1.default.CONNECTION, connection);
|
|
203
|
+
}
|
|
204
|
+
getConnections() {
|
|
205
|
+
return this.connections;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
exports.default = HttpServer;
|
|
209
|
+
//# sourceMappingURL=http-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-server.js","sourceRoot":"","sources":["../../src/http-server.ts"],"names":[],"mappings":";;;;;AACA,gDAAwB;AACxB,gDAAwB;AACxB,kDAA0B;AAE1B,4CAA2B;AAE3B,oCAA8C;AAC9C,wCAA0C;AAC1C,oCAA4D;AAC5D,0CAA6C;AAC7C,+EAAsD;AACtD,kCAA4C;AAE5C,8DAAsC;AACtC,gEAAwC;AACxC,gDAA8B;AAG9B,qEAA4C;AAC5C,qEAAqD;AAGrD,sFAA6D;AAG7D,MAAM,UAAW,SAAQ,cAAU;IAOlC,YACC,OAAsB,EACtB,UAAuC;QAEvC,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC9B,UAAU,GAAG,cAAI,CAAC,YAAY,EAAE,CAAC;QAClC,CAAC;QAED,KAAK,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAE3B,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAEhC,MAAM,MAAM,GAAG,IAAI,gBAAM,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE;YAC9C,OAAO,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,CAAC,MAAM,CAAC,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;IACvB,CAAC;IAEM,KAAK,CAAC,IAAI;QAChB,MAAM,KAAK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;QAE1C,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAE7B,IAAI,CAAC,IAAI,CAAC,sBAAW,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAC/C,CAAC;IAEO,cAAc;QACrB,OAAO,IAAI,CAAC,WAAW,CAAC;IACzB,CAAC;CACD;AAED,kBAAe,UAAU,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { default as HttpServer } from './http';
|
|
2
|
-
export { default as Middleware } from './http/middleware';
|
|
3
|
-
export { default as Endpoint } from './http/endpoint';
|
|
4
|
-
export { default as createServer } from './http/utility/create-server';
|
|
5
|
-
export { default as HtmlResultSerializer } from './http/result-serializer/html';
|
|
1
|
+
export { default as HttpServer } from './http-server';
|
|
2
|
+
export { default as Middleware } from './http-server/middleware';
|
|
3
|
+
export { default as Endpoint } from './http-server/endpoint';
|
|
4
|
+
export { default as createServer } from './http-server/utility/create-server';
|
|
5
|
+
export { default as HtmlResultSerializer } from './http-server/result-serializer/html';
|
package/dist/src/index.js
CHANGED
|
@@ -4,14 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.HtmlResultSerializer = exports.createServer = exports.Endpoint = exports.Middleware = exports.HttpServer = void 0;
|
|
7
|
-
var
|
|
8
|
-
Object.defineProperty(exports, "HttpServer", { enumerable: true, get: function () { return __importDefault(
|
|
9
|
-
var middleware_1 = require("./http/middleware.js");
|
|
7
|
+
var http_server_1 = require("./http-server.js");
|
|
8
|
+
Object.defineProperty(exports, "HttpServer", { enumerable: true, get: function () { return __importDefault(http_server_1).default; } });
|
|
9
|
+
var middleware_1 = require("./http-server/middleware.js");
|
|
10
10
|
Object.defineProperty(exports, "Middleware", { enumerable: true, get: function () { return __importDefault(middleware_1).default; } });
|
|
11
|
-
var endpoint_1 = require("./http/endpoint.js");
|
|
11
|
+
var endpoint_1 = require("./http-server/endpoint.js");
|
|
12
12
|
Object.defineProperty(exports, "Endpoint", { enumerable: true, get: function () { return __importDefault(endpoint_1).default; } });
|
|
13
|
-
var create_server_1 = require("./http/utility/create-server.js");
|
|
13
|
+
var create_server_1 = require("./http-server/utility/create-server.js");
|
|
14
14
|
Object.defineProperty(exports, "createServer", { enumerable: true, get: function () { return __importDefault(create_server_1).default; } });
|
|
15
|
-
var html_1 = require("./http/result-serializer/html.js");
|
|
15
|
+
var html_1 = require("./http-server/result-serializer/html.js");
|
|
16
16
|
Object.defineProperty(exports, "HtmlResultSerializer", { enumerable: true, get: function () { return __importDefault(html_1).default; } });
|
|
17
17
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAkD;AAA1C,0HAAA,OAAO,OAAc;AAC7B,qDAA6D;AAArD,yHAAA,OAAO,OAAc;AAC7B,iDAAyD;AAAjD,qHAAA,OAAO,OAAY;AAC3B,mEAA0E;AAAlE,8HAAA,OAAO,OAAgB;AAC/B,2DAAmF;AAA3E,6HAAA,OAAO,OAAwB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { NetworkProtocol } from '@fc3/network';
|
|
2
|
+
import BaseServer from './base';
|
|
3
|
+
import ServerOptions from './type/server-options';
|
|
4
|
+
declare class TcpServer extends BaseServer {
|
|
5
|
+
private connections;
|
|
6
|
+
constructor(options: ServerOptions);
|
|
7
|
+
protected bindHandlers(): void;
|
|
8
|
+
protected getProtocol(): NetworkProtocol;
|
|
9
|
+
private handleSocket;
|
|
10
|
+
private addConnection;
|
|
11
|
+
private getConnections;
|
|
12
|
+
}
|
|
13
|
+
export default TcpServer;
|