@fc3/server 0.1.3 → 0.1.5
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.d.ts +1 -1
- package/dist/src/http-server/route.js +2 -3
- package/dist/src/http-server/route.js.map +1 -1
- package/dist/src/http-server/utility/create-server.d.ts +1 -1
- package/dist/src/http-server/utility/create-server.js +1 -1
- package/dist/src/http-server/utility/parse-path.d.ts +6 -0
- package/dist/src/{http/utility/path-parser.js → http-server/utility/parse-path.js} +6 -2
- package/dist/src/http-server/utility/parse-path.js.map +1 -0
- package/dist/src/http-server.d.ts +1 -1
- package/dist/src/http-server.js +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +3 -1
- package/dist/src/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/src/http/endpoint/ping.d.ts +0 -12
- package/dist/src/http/endpoint/ping.js +0 -22
- package/dist/src/http/endpoint/ping.js.map +0 -1
- package/dist/src/http/endpoint.d.ts +0 -47
- package/dist/src/http/endpoint.js +0 -216
- package/dist/src/http/endpoint.js.map +0 -1
- package/dist/src/http/interface/endpoint-constructor.d.ts +0 -5
- package/dist/src/http/interface/endpoint-constructor.js +0 -4
- package/dist/src/http/interface/endpoint-constructor.js.map +0 -1
- package/dist/src/http/interface/result-serializer.d.ts +0 -4
- package/dist/src/http/interface/result-serializer.js +0 -3
- package/dist/src/http/interface/result-serializer.js.map +0 -1
- package/dist/src/http/middleware.d.ts +0 -6
- package/dist/src/http/middleware.js +0 -9
- package/dist/src/http/middleware.js.map +0 -1
- package/dist/src/http/result-serializer/html.d.ts +0 -16
- package/dist/src/http/result-serializer/html.js +0 -74
- package/dist/src/http/result-serializer/html.js.map +0 -1
- package/dist/src/http/result-serializer/json.d.ts +0 -8
- package/dist/src/http/result-serializer/json.js +0 -17
- package/dist/src/http/result-serializer/json.js.map +0 -1
- package/dist/src/http/route.d.ts +0 -21
- package/dist/src/http/route.js +0 -73
- package/dist/src/http/route.js.map +0 -1
- package/dist/src/http/router.d.ts +0 -20
- package/dist/src/http/router.js +0 -78
- package/dist/src/http/router.js.map +0 -1
- package/dist/src/http/type/session-resolver.d.ts +0 -6
- package/dist/src/http/type/session-resolver.js +0 -3
- package/dist/src/http/type/session-resolver.js.map +0 -1
- package/dist/src/http/utility/create-server.d.ts +0 -10
- package/dist/src/http/utility/create-server.js +0 -24
- package/dist/src/http/utility/create-server.js.map +0 -1
- package/dist/src/http/utility/path-parser.d.ts +0 -11
- package/dist/src/http/utility/path-parser.js.map +0 -1
- package/dist/src/http/utility/standardize-html-indentation.d.ts +0 -2
- package/dist/src/http/utility/standardize-html-indentation.js +0 -44
- package/dist/src/http/utility/standardize-html-indentation.js.map +0 -1
- package/dist/src/http/websocket-wrapper.d.ts +0 -21
- package/dist/src/http/websocket-wrapper.js +0 -56
- package/dist/src/http/websocket-wrapper.js.map +0 -1
- package/dist/src/http.d.ts +0 -40
- package/dist/src/http.js +0 -209
- package/dist/src/http.js.map +0 -1
- package/dist/src/tcp.d.ts +0 -13
- package/dist/src/tcp.js +0 -41
- package/dist/src/tcp.js.map +0 -1
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const key_generator_1 = __importDefault(require("@fc3/key-generator"));
|
|
8
|
-
const http_1 = require("@fc3/http");
|
|
9
|
-
const errors_1 = require("@fc3/errors");
|
|
10
|
-
const json_1 = __importDefault(require("./result-serializer/json.js"));
|
|
11
|
-
class Endpoint {
|
|
12
|
-
setRequest(request) {
|
|
13
|
-
this.request = request;
|
|
14
|
-
}
|
|
15
|
-
setResponse(response) {
|
|
16
|
-
this.response = response;
|
|
17
|
-
}
|
|
18
|
-
async serve() {
|
|
19
|
-
const result = await this.serveInternal();
|
|
20
|
-
if (result === undefined) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
this.applyNecessaryHeaders();
|
|
24
|
-
const response = this.getResponse();
|
|
25
|
-
if (typeof result === 'string' || result instanceof Buffer) {
|
|
26
|
-
response.send(result);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const serialized_result = await this.serializeResult(result);
|
|
30
|
-
response.send(serialized_result);
|
|
31
|
-
}
|
|
32
|
-
getRequest() {
|
|
33
|
-
if (this.request === undefined) {
|
|
34
|
-
throw new errors_1.InvariantViolation('Tried to read request, but it was not set');
|
|
35
|
-
}
|
|
36
|
-
return this.request;
|
|
37
|
-
}
|
|
38
|
-
getNativeRequest() {
|
|
39
|
-
const request = this.getRequest();
|
|
40
|
-
return request.getNativeRequest();
|
|
41
|
-
}
|
|
42
|
-
getResponse() {
|
|
43
|
-
if (this.response === undefined) {
|
|
44
|
-
throw new errors_1.InvariantViolation(`
|
|
45
|
-
Tried to read response, but it was not setttt
|
|
46
|
-
`);
|
|
47
|
-
}
|
|
48
|
-
return this.response;
|
|
49
|
-
}
|
|
50
|
-
getNativeResponse() {
|
|
51
|
-
const response = this.getResponse();
|
|
52
|
-
return response.getNativeResponse();
|
|
53
|
-
}
|
|
54
|
-
getPathParameter(parameter) {
|
|
55
|
-
const request = this.getRequest();
|
|
56
|
-
const value = request.getPathParameter(parameter);
|
|
57
|
-
if (value === undefined) {
|
|
58
|
-
throw new errors_1.InvalidError(`
|
|
59
|
-
No value found for path parameter "${parameter}"
|
|
60
|
-
`);
|
|
61
|
-
}
|
|
62
|
-
return value;
|
|
63
|
-
}
|
|
64
|
-
getQueryParameter(parameter) {
|
|
65
|
-
const request = this.getRequest();
|
|
66
|
-
return request.getQueryParameter(parameter);
|
|
67
|
-
}
|
|
68
|
-
getNumericParameter(parameter, fallback) {
|
|
69
|
-
const raw_value = this.getQueryParameter(parameter);
|
|
70
|
-
if (raw_value === undefined) {
|
|
71
|
-
if (fallback === undefined) {
|
|
72
|
-
throw new errors_1.InvalidError(`Query parameter not found: ${parameter}`);
|
|
73
|
-
}
|
|
74
|
-
return fallback;
|
|
75
|
-
}
|
|
76
|
-
if (typeof raw_value !== 'string') {
|
|
77
|
-
throw new errors_1.InvalidError(`
|
|
78
|
-
Invalid numeric value for parameter ${parameter}: ${raw_value}
|
|
79
|
-
`);
|
|
80
|
-
}
|
|
81
|
-
const parsed_value = parseFloat(raw_value);
|
|
82
|
-
if (isNaN(parsed_value)) {
|
|
83
|
-
throw new errors_1.InvalidError(`
|
|
84
|
-
Invalid numeric value for parameter ${parameter}: ${raw_value}
|
|
85
|
-
`);
|
|
86
|
-
}
|
|
87
|
-
return parsed_value;
|
|
88
|
-
}
|
|
89
|
-
setStatusCode(status_code) {
|
|
90
|
-
const response = this.getResponse();
|
|
91
|
-
response.setStatusCode(status_code);
|
|
92
|
-
}
|
|
93
|
-
getRequestBody() {
|
|
94
|
-
const request = this.getRequest();
|
|
95
|
-
const data = request.getData();
|
|
96
|
-
return data;
|
|
97
|
-
}
|
|
98
|
-
getLogger() {
|
|
99
|
-
const execution_context = this.getExecutionContext();
|
|
100
|
-
return execution_context.getLogger();
|
|
101
|
-
}
|
|
102
|
-
getExecutionContext() {
|
|
103
|
-
const request = this.getRequest();
|
|
104
|
-
return request.getExecutionContext();
|
|
105
|
-
}
|
|
106
|
-
applyCorsHeaders(request, response) {
|
|
107
|
-
const origin = request.getAllowedCorsOrigin();
|
|
108
|
-
response.setHeaderValue(http_1.HttpHeader.ACCESS_CONTROL_ALLOW_ORIGIN, origin);
|
|
109
|
-
const allowed_headers = request.getAllowedCorsHeaders();
|
|
110
|
-
const header_string = allowed_headers.join(',');
|
|
111
|
-
response.setHeaderValue(http_1.HttpHeader.ACCESS_CONTROL_ALLOW_HEADERS, header_string);
|
|
112
|
-
response.setHeaderValue(http_1.HttpHeader.ACCESS_CONTROL_ALLOW_CREDENTIALS, 'true');
|
|
113
|
-
}
|
|
114
|
-
getSessionId() {
|
|
115
|
-
const { id } = this.getSession();
|
|
116
|
-
return id;
|
|
117
|
-
}
|
|
118
|
-
setSession(session) {
|
|
119
|
-
const response = this.getResponse();
|
|
120
|
-
const serializer = new http_1.CookieSerializer(session.id);
|
|
121
|
-
const cookie_value = serializer.serialize();
|
|
122
|
-
const execution_context = this.getExecutionContext();
|
|
123
|
-
execution_context.setSession(session);
|
|
124
|
-
response.setHeaderValue(http_1.HttpHeader.SET_COOKIE, cookie_value);
|
|
125
|
-
return session;
|
|
126
|
-
}
|
|
127
|
-
getSession() {
|
|
128
|
-
const request = this.getRequest();
|
|
129
|
-
const execution_context = this.getExecutionContext();
|
|
130
|
-
const session = execution_context.getSession();
|
|
131
|
-
const session_id = request.getSessionIdFromCookie();
|
|
132
|
-
if (session_id === undefined || session === undefined || session_id !== session.id) {
|
|
133
|
-
return this.setSession({
|
|
134
|
-
id: key_generator_1.default.generateToken(),
|
|
135
|
-
account_id: null,
|
|
136
|
-
username: null
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
return session;
|
|
140
|
-
}
|
|
141
|
-
getJsonResultSerializer(result) {
|
|
142
|
-
return new json_1.default(result);
|
|
143
|
-
}
|
|
144
|
-
getHtmlResultSerializer(_result) {
|
|
145
|
-
throw new errors_1.NotImplementedError('Must implement getHtmlResultSerializer in child class');
|
|
146
|
-
}
|
|
147
|
-
async authorize() {
|
|
148
|
-
// Noop by default, override this in child classes.
|
|
149
|
-
}
|
|
150
|
-
async serveInternal() {
|
|
151
|
-
await this.authorize();
|
|
152
|
-
await this.parseBody();
|
|
153
|
-
return this.process();
|
|
154
|
-
}
|
|
155
|
-
async serializeResult(result) {
|
|
156
|
-
const serializer = await this.getResultSerializer(result);
|
|
157
|
-
return serializer.serialize();
|
|
158
|
-
}
|
|
159
|
-
getResultSerializer(result) {
|
|
160
|
-
const content_type = this.getContentType();
|
|
161
|
-
switch (content_type) {
|
|
162
|
-
case http_1.ContentType.JSON:
|
|
163
|
-
return this.getJsonResultSerializer(result);
|
|
164
|
-
case http_1.ContentType.HTML:
|
|
165
|
-
return this.getHtmlResultSerializer(result);
|
|
166
|
-
default:
|
|
167
|
-
throw new Error(`Unable to serialize result for content type: ${content_type}`);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
parseBody() {
|
|
171
|
-
const request = this.getRequest();
|
|
172
|
-
return request.parseBody();
|
|
173
|
-
}
|
|
174
|
-
applyNecessaryHeaders() {
|
|
175
|
-
this.applyContentTypeHeader();
|
|
176
|
-
}
|
|
177
|
-
applyContentTypeHeader() {
|
|
178
|
-
const content_type = this.getContentType();
|
|
179
|
-
const response = this.getResponse();
|
|
180
|
-
response.setHeaderValue(http_1.HttpHeader.CONTENT_TYPE, content_type);
|
|
181
|
-
}
|
|
182
|
-
getContentType() {
|
|
183
|
-
if (this.content_type === undefined) {
|
|
184
|
-
this.content_type = this.determineContentType();
|
|
185
|
-
}
|
|
186
|
-
return this.content_type;
|
|
187
|
-
}
|
|
188
|
-
determineContentType() {
|
|
189
|
-
const supported_content_types = this.getContentTypes();
|
|
190
|
-
if (supported_content_types.length === 1) {
|
|
191
|
-
return supported_content_types[0];
|
|
192
|
-
}
|
|
193
|
-
const request = this.getRequest();
|
|
194
|
-
const accepted_content_types = request.getAcceptedContentTypes();
|
|
195
|
-
const has_any_type = accepted_content_types.includes(http_1.ContentType.ANY);
|
|
196
|
-
const matching_type = accepted_content_types.find((content_type) => {
|
|
197
|
-
return supported_content_types.includes(content_type);
|
|
198
|
-
});
|
|
199
|
-
if (matching_type !== undefined) {
|
|
200
|
-
return matching_type;
|
|
201
|
-
}
|
|
202
|
-
if (has_any_type && supported_content_types.includes(http_1.ContentType.JSON)) {
|
|
203
|
-
return http_1.ContentType.JSON;
|
|
204
|
-
}
|
|
205
|
-
throw new errors_1.NotFoundError(`
|
|
206
|
-
No matching content types found for this request
|
|
207
|
-
supported content types: ${supported_content_types}
|
|
208
|
-
accepted content types: ${accepted_content_types}
|
|
209
|
-
`);
|
|
210
|
-
}
|
|
211
|
-
getContentTypes() {
|
|
212
|
-
return this.content_types;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
exports.default = Endpoint;
|
|
216
|
-
//# sourceMappingURL=endpoint.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../../../src/http/endpoint.ts"],"names":[],"mappings":";AAAA,iDAAiD;;;;;AAQjD,uEAA8C;AAG9C,oCAQmB;AACnB,wCAKqB;AAGrB,uEAA+D;AAO/D,MAAe,QAAQ;IASf,UAAU,CAAC,OAAwB;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAEM,WAAW,CAAC,QAA0B;QAC5C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;IAEM,KAAK,CAAC,KAAK;QACjB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAA;QAEzC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO;QACR,CAAC;QAED,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAE7B,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAEpC,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,YAAY,MAAM,EAAE,CAAC;YAC5D,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACtB,OAAO;QACR,CAAC;QAED,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,MAAgB,CAAC,CAAC;QAEvE,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAClC,CAAC;IAES,UAAU;QACnB,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YAChC,MAAM,IAAI,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AAI,CAAC,aAAa,CAAC;IAC3B,CAAC;CAGD;AAED,kBAAe,QAAQ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint-constructor.js","sourceRoot":"","sources":["../../../../src/http/interface/endpoint-constructor.ts"],"names":[],"mappings":";AAAA,iDAAiD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"result-serializer.js","sourceRoot":"","sources":["../../../../src/http/interface/result-serializer.ts"],"names":[],"mappings":""}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { IncomingRequest, OutgoingResponse } from '@fc3/http';
|
|
2
|
-
declare abstract class Middleware {
|
|
3
|
-
abstract handleRequest(request: IncomingRequest, response: OutgoingResponse): Promise<boolean>;
|
|
4
|
-
handleError(error: Error, request: IncomingRequest, response: OutgoingResponse): Promise<boolean>;
|
|
5
|
-
}
|
|
6
|
-
export default Middleware;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/http/middleware.ts"],"names":[],"mappings":";;AAEA,MAAe,UAAU;IAMjB,KAAK,CAAC,WAAW,CACvB,KAAY,EACZ,OAAwB,EACxB,QAA0B;QAE1B,OAAO,KAAK,CAAC;IACd,CAAC;CACD;AAED,kBAAe,UAAU,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import ResultSerializer from './../interface/result-serializer';
|
|
2
|
-
declare abstract class HtmlResultSerializer<ResultType extends object> implements ResultSerializer {
|
|
3
|
-
private result;
|
|
4
|
-
constructor(result: ResultType);
|
|
5
|
-
serialize(): string;
|
|
6
|
-
protected getResult(): ResultType;
|
|
7
|
-
protected getCssUrls(): string[];
|
|
8
|
-
protected serializeCss(): string;
|
|
9
|
-
protected getBodyClass(): string;
|
|
10
|
-
private serializeLinkTags;
|
|
11
|
-
protected serializeMetaTags(): string;
|
|
12
|
-
protected getMetaMappings(): Record<string, string | number | boolean>;
|
|
13
|
-
abstract serializeContent(): string;
|
|
14
|
-
protected abstract getTitle(): string;
|
|
15
|
-
}
|
|
16
|
-
export default HtmlResultSerializer;
|
|
@@ -1,74 +0,0 @@
|
|
|
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 standardize_html_indentation_1 = __importDefault(require("./../utility/standardize-html-indentation.js"));
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
8
|
-
class HtmlResultSerializer {
|
|
9
|
-
constructor(result) {
|
|
10
|
-
this.result = result;
|
|
11
|
-
}
|
|
12
|
-
serialize() {
|
|
13
|
-
const title = this.getTitle();
|
|
14
|
-
const content = this.serializeContent();
|
|
15
|
-
const link_tags = this.serializeLinkTags();
|
|
16
|
-
const meta_tags = this.serializeMetaTags();
|
|
17
|
-
const body_class = this.getBodyClass();
|
|
18
|
-
const css = this.serializeCss();
|
|
19
|
-
const html = `
|
|
20
|
-
<!doctype html>
|
|
21
|
-
<html>
|
|
22
|
-
<head>
|
|
23
|
-
<meta charset="UTF-8">
|
|
24
|
-
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
|
|
25
|
-
<meta content="utf-8" http-equiv="encoding" />
|
|
26
|
-
<meta name="viewport" content="width=640, user-scalable=no">
|
|
27
|
-
<meta name="robots" content="noindex" />
|
|
28
|
-
<link rel="icon" href="/public/favicon.ico" type="image/x-icon">
|
|
29
|
-
<title>${title}</title>
|
|
30
|
-
${meta_tags}
|
|
31
|
-
${link_tags}
|
|
32
|
-
${css}
|
|
33
|
-
</head>
|
|
34
|
-
<body class="${body_class}">
|
|
35
|
-
${content}
|
|
36
|
-
</body>
|
|
37
|
-
</html>
|
|
38
|
-
`;
|
|
39
|
-
return (0, standardize_html_indentation_1.default)(html);
|
|
40
|
-
}
|
|
41
|
-
getResult() {
|
|
42
|
-
return this.result;
|
|
43
|
-
}
|
|
44
|
-
// Override this as necessary on child classes:
|
|
45
|
-
getCssUrls() {
|
|
46
|
-
return [];
|
|
47
|
-
}
|
|
48
|
-
serializeCss() {
|
|
49
|
-
return '';
|
|
50
|
-
}
|
|
51
|
-
getBodyClass() {
|
|
52
|
-
return '';
|
|
53
|
-
}
|
|
54
|
-
serializeLinkTags() {
|
|
55
|
-
const css_urls = this.getCssUrls();
|
|
56
|
-
const serialized_links = css_urls.map((url) => {
|
|
57
|
-
return `<link rel="stylesheet" href="${url}">`;
|
|
58
|
-
});
|
|
59
|
-
return serialized_links.join('\n');
|
|
60
|
-
}
|
|
61
|
-
serializeMetaTags() {
|
|
62
|
-
const meta_mappings = this.getMetaMappings();
|
|
63
|
-
const serialized_tags = Object.entries(meta_mappings).map((tuple) => {
|
|
64
|
-
const [key, value] = tuple;
|
|
65
|
-
return `<meta name="${key}" content="${value}" />`;
|
|
66
|
-
});
|
|
67
|
-
return serialized_tags.join('\n');
|
|
68
|
-
}
|
|
69
|
-
getMetaMappings() {
|
|
70
|
-
return {};
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
exports.default = HtmlResultSerializer;
|
|
74
|
-
//# sourceMappingURL=html.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"html.js","sourceRoot":"","sources":["../../../../src/http/result-serializer/html.ts"],"names":[],"mappings":";;;;;AACA,6GAAmF;AAEnF,wDAAwD;AACxD,MAAe,oBAAoB;IAIlC,YAAmB,MAAkB;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAEM,SAAS;QACf,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxC,MAAM,SAAS,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC3C,MAAM,SAAS,GAAG,IAAI,CAAC,i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AAe,oBAAoB,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import ResultSerializer from './../interface/result-serializer';
|
|
2
|
-
declare class JsonResultSerializer<ResultType extends object> implements ResultSerializer {
|
|
3
|
-
private result;
|
|
4
|
-
constructor(result: ResultType);
|
|
5
|
-
serialize(): string;
|
|
6
|
-
protected getResult(): ResultType;
|
|
7
|
-
}
|
|
8
|
-
export default JsonResultSerializer;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
4
|
-
class JsonResultSerializer {
|
|
5
|
-
constructor(result) {
|
|
6
|
-
this.result = result;
|
|
7
|
-
}
|
|
8
|
-
serialize() {
|
|
9
|
-
const result = this.getResult();
|
|
10
|
-
return JSON.stringify(result);
|
|
11
|
-
}
|
|
12
|
-
getResult() {
|
|
13
|
-
return this.result;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.default = JsonResultSerializer;
|
|
17
|
-
//# sourceMappingURL=json.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../../../src/http/result-serializer/json.ts"],"names":[],"mappings":";;AAEA,wDAAwD;AACxD,MAAM,oBAAoB;IAIzB,YAAmB,MAAkB;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAEM,SAAS;QACf,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAEhC,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IAES,SAAS;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;CACD;AAED,kBAAe,oBAAoB,CAAC"}
|
package/dist/src/http/route.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { HttpMethod, ContentType, PathParameters, IncomingRequest, OutgoingResponse } from '@fc3/http';
|
|
2
|
-
import EndpointConstructor from './interface/endpoint-constructor';
|
|
3
|
-
import Endpoint from './endpoint';
|
|
4
|
-
declare class Route {
|
|
5
|
-
private endpoint_constructor;
|
|
6
|
-
private method;
|
|
7
|
-
private content_types;
|
|
8
|
-
private regex;
|
|
9
|
-
private parameter_keys;
|
|
10
|
-
constructor(endpoint_constructor: EndpointConstructor);
|
|
11
|
-
getMethod(): HttpMethod;
|
|
12
|
-
matchesPath(path: string): boolean;
|
|
13
|
-
matchesContentTypes(content_types: ContentType[]): boolean;
|
|
14
|
-
buildEndpoint(request: IncomingRequest, response: OutgoingResponse): Promise<Endpoint<any, any>>;
|
|
15
|
-
getPathParametersForRequest(request: IncomingRequest): PathParameters;
|
|
16
|
-
private getEndpointConstructor;
|
|
17
|
-
private getParameterKeys;
|
|
18
|
-
private getRegex;
|
|
19
|
-
private getContentTypes;
|
|
20
|
-
}
|
|
21
|
-
export default Route;
|
package/dist/src/http/route.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
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 path_parser_1 = __importDefault(require("./utility/path-parser.js"));
|
|
8
|
-
class Route {
|
|
9
|
-
constructor(endpoint_constructor) {
|
|
10
|
-
this.endpoint_constructor = endpoint_constructor;
|
|
11
|
-
const throwaway_endpoint = new endpoint_constructor();
|
|
12
|
-
this.method = throwaway_endpoint.method;
|
|
13
|
-
this.content_types = throwaway_endpoint.content_types;
|
|
14
|
-
const path = throwaway_endpoint.path;
|
|
15
|
-
const parser = new path_parser_1.default(path);
|
|
16
|
-
const parsed_path = parser.parse();
|
|
17
|
-
this.regex = parsed_path.regex;
|
|
18
|
-
this.parameter_keys = parsed_path.parameter_keys;
|
|
19
|
-
}
|
|
20
|
-
getMethod() {
|
|
21
|
-
return this.method;
|
|
22
|
-
}
|
|
23
|
-
matchesPath(path) {
|
|
24
|
-
return this.regex.test(path);
|
|
25
|
-
}
|
|
26
|
-
matchesContentTypes(content_types) {
|
|
27
|
-
if (content_types.length === 0) {
|
|
28
|
-
// If the user agent didn't specify any accepted content types,
|
|
29
|
-
// they are going to have to live with whatever they get back.
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
const route_content_types = this.getContentTypes();
|
|
33
|
-
return content_types.some((content_type) => {
|
|
34
|
-
return route_content_types.includes(content_type);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
async buildEndpoint(request, response) {
|
|
38
|
-
const endpoint_constructor = this.getEndpointConstructor();
|
|
39
|
-
const endpoint = new endpoint_constructor();
|
|
40
|
-
endpoint.setRequest(request);
|
|
41
|
-
endpoint.setResponse(response);
|
|
42
|
-
return endpoint;
|
|
43
|
-
}
|
|
44
|
-
getPathParametersForRequest(request) {
|
|
45
|
-
const path = request.getPath();
|
|
46
|
-
const regex = this.getRegex();
|
|
47
|
-
const match = path.match(regex);
|
|
48
|
-
const result = {};
|
|
49
|
-
if (match === null) {
|
|
50
|
-
return result;
|
|
51
|
-
}
|
|
52
|
-
const parameter_keys = this.getParameterKeys();
|
|
53
|
-
parameter_keys.forEach((parameter_key, index) => {
|
|
54
|
-
const parameter_value = match[index + 1];
|
|
55
|
-
result[parameter_key] = parameter_value;
|
|
56
|
-
});
|
|
57
|
-
return result;
|
|
58
|
-
}
|
|
59
|
-
getEndpointConstructor() {
|
|
60
|
-
return this.endpoint_constructor;
|
|
61
|
-
}
|
|
62
|
-
getParameterKeys() {
|
|
63
|
-
return this.parameter_keys;
|
|
64
|
-
}
|
|
65
|
-
getRegex() {
|
|
66
|
-
return this.regex;
|
|
67
|
-
}
|
|
68
|
-
getContentTypes() {
|
|
69
|
-
return [...this.content_types, http_1.ContentType.ANY];
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
exports.default = Route;
|
|
73
|
-
//# sourceMappingURL=route.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"route.js","sourceRoot":"","sources":["../../../src/http/route.ts"],"names":[],"mappings":";;;;;AAAA,oCAAqG;AAGrG,2EAAkD;AAGlD,MAAM,KAAK;IAQV,YAAmB,oBAAyC;QAC3D,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;QAEjD,MAAM,kBAAkB,GAAG,IAAI,oBAAoB,EAAE,CAAC;QAEtD,IAAI,CAAC,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAC;QACxC,IAAI,CAAC,aAAa,GAAG,kBAAkB,CAAC,aAAa,CAAC;QAEtD,MAAM,IAAI,GAAG,kBAAkB,CAAC,IAAI,CAAC;QACrC,MAAM,MAAM,GAAG,IAAI,qBAAU,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;QAEnC,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC;QAC/B,IAAI,CAAC,cAAc,GAAG,WAAW,CAAC,cAAc,CAAC;IAClD,CAAC;IAEM,SAAS;QACf,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IAEM,WAAW,CAAC,IAAY;QAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAEM,mBAAmB,CAAC,aAA4B;QACtD,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAChC,+DAA+D;YAC/D,8DAA8D;YAC9D,OAAO,IAAI,CAAC;QACb,CAAC;QAED,MAAM,mBAAmB,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QAEnD,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE;YAC1C,OAAO,mBAAmB,CAAC,QAAQ,CAAC,YAA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CAAC,GAAG,CAAC,CAAC;IACjD,CAAC;CACD;AAED,kBAAe,KAAK,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import Logger from '@fc3/logger';
|
|
2
|
-
import { IncomingRequest, OutgoingResponse } from '@fc3/http';
|
|
3
|
-
import Middleware from './middleware';
|
|
4
|
-
import Route from './route';
|
|
5
|
-
import Endpoint from './endpoint';
|
|
6
|
-
interface EndpointSetupCallback {
|
|
7
|
-
(endpoint: Endpoint<any, any>): Promise<void>;
|
|
8
|
-
}
|
|
9
|
-
declare class Router extends Middleware {
|
|
10
|
-
private logger;
|
|
11
|
-
private method_routes;
|
|
12
|
-
private endpoint_setup_callback;
|
|
13
|
-
constructor(logger: Logger, endpoint_setup_callback?: EndpointSetupCallback);
|
|
14
|
-
addRoute(route: Route): void;
|
|
15
|
-
handleRequest(request: IncomingRequest, response: OutgoingResponse): Promise<boolean>;
|
|
16
|
-
private getRoutesForMethod;
|
|
17
|
-
private getMethodRoutes;
|
|
18
|
-
private getLogger;
|
|
19
|
-
}
|
|
20
|
-
export default Router;
|
package/dist/src/http/router.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../../src/http/router.ts"],"names":[],"mappings":";;;;;AACA,oCAAwE;AAExE,iEAAyC;AAkBzC,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,MAA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AAM,KAAK,GAAG,cAAc,CAAC;QAE7B,MAAM,eAAe,GAAG,KAAK,CAAC,2BAA2B,CAAC,OAAO,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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"session-resolver.js","sourceRoot":"","sources":["../../../../src/http/type/session-resolver.ts"],"names":[],"mappings":""}
|
|
@@ -1,10 +0,0 @@
|
|
|
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;
|