@miqro/core 4.0.1 → 5.0.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/build/app.d.ts +15 -11
- package/build/app.js +22 -20
- package/build/app.js.map +1 -1
- package/build/common.d.ts +106 -0
- package/build/common.js +477 -0
- package/build/common.js.map +1 -0
- package/build/lib.d.ts +7 -38
- package/build/lib.js +6 -33
- package/build/lib.js.map +1 -1
- package/build/middleware/body-parser.d.ts +78 -0
- package/build/middleware/body-parser.js +548 -0
- package/build/middleware/body-parser.js.map +1 -0
- package/build/middleware/router.d.ts +114 -0
- package/build/middleware/router.js +704 -0
- package/build/middleware/router.js.map +1 -0
- package/build/middleware/session.d.ts +27 -3
- package/build/middleware/session.js +238 -18
- package/build/middleware/session.js.map +1 -1
- package/build/types.d.ts +309 -0
- package/build/types.js +455 -0
- package/build/types.js.map +1 -0
- package/build/{websocket/cluster.d.ts → websocket.d.ts} +13 -2
- package/build/websocket.js +316 -0
- package/build/websocket.js.map +1 -0
- package/package.json +7 -7
- package/src/app.ts +36 -32
- package/src/common.ts +528 -0
- package/src/lib.ts +63 -101
- package/src/middleware/body-parser.ts +593 -0
- package/src/middleware/router.ts +840 -0
- package/src/middleware/session.ts +249 -19
- package/src/types.ts +785 -0
- package/src/websocket.ts +356 -0
- package/build/api-router.d.ts +0 -34
- package/build/api-router.js +0 -48
- package/build/api-router.js.map +0 -1
- package/build/app-utils.d.ts +0 -13
- package/build/app-utils.js +0 -78
- package/build/app-utils.js.map +0 -1
- package/build/common/api-router-types.d.ts +0 -28
- package/build/common/api-router-types.js +0 -24
- package/build/common/api-router-types.js.map +0 -1
- package/build/common/api-router-utils.d.ts +0 -3
- package/build/common/api-router-utils.js +0 -118
- package/build/common/api-router-utils.js.map +0 -1
- package/build/common/config/config.d.ts +0 -15
- package/build/common/config/config.js +0 -38
- package/build/common/config/config.js.map +0 -1
- package/build/common/config/featuretoggle.d.ts +0 -1
- package/build/common/config/featuretoggle.js +0 -6
- package/build/common/config/featuretoggle.js.map +0 -1
- package/build/common/config/loader.d.ts +0 -13
- package/build/common/config/loader.js +0 -64
- package/build/common/config/loader.js.map +0 -1
- package/build/common/context.d.ts +0 -57
- package/build/common/context.js +0 -137
- package/build/common/context.js.map +0 -1
- package/build/common/error/badrequesterror.d.ts +0 -3
- package/build/common/error/badrequesterror.js +0 -7
- package/build/common/error/badrequesterror.js.map +0 -1
- package/build/common/error/configfilenotfound.d.ts +0 -3
- package/build/common/error/configfilenotfound.js +0 -7
- package/build/common/error/configfilenotfound.js.map +0 -1
- package/build/common/error/forbiddenerror.d.ts +0 -3
- package/build/common/error/forbiddenerror.js +0 -7
- package/build/common/error/forbiddenerror.js.map +0 -1
- package/build/common/error/notfound.d.ts +0 -3
- package/build/common/error/notfound.js +0 -7
- package/build/common/error/notfound.js.map +0 -1
- package/build/common/error/notimplemented.d.ts +0 -3
- package/build/common/error/notimplemented.js +0 -7
- package/build/common/error/notimplemented.js.map +0 -1
- package/build/common/error/unauthorizederror.d.ts +0 -3
- package/build/common/error/unauthorizederror.js +0 -7
- package/build/common/error/unauthorizederror.js.map +0 -1
- package/build/common/logger/constants.d.ts +0 -14
- package/build/common/logger/constants.js +0 -22
- package/build/common/logger/constants.js.map +0 -1
- package/build/common/logger/factory.d.ts +0 -16
- package/build/common/logger/factory.js +0 -47
- package/build/common/logger/factory.js.map +0 -1
- package/build/common/logger/interfaces.d.ts +0 -18
- package/build/common/logger/interfaces.js +0 -2
- package/build/common/logger/interfaces.js.map +0 -1
- package/build/common/logger/logger.d.ts +0 -35
- package/build/common/logger/logger.js +0 -95
- package/build/common/logger/logger.js.map +0 -1
- package/build/common/logger/transport/console.d.ts +0 -5
- package/build/common/logger/transport/console.js +0 -37
- package/build/common/logger/transport/console.js.map +0 -1
- package/build/common/logger/transport/file.d.ts +0 -2
- package/build/common/logger/transport/file.js +0 -25
- package/build/common/logger/transport/file.js.map +0 -1
- package/build/common/parser.d.ts +0 -7
- package/build/common/parser.js +0 -44
- package/build/common/parser.js.map +0 -1
- package/build/common/router-default-logger-factory.d.ts +0 -4
- package/build/common/router-default-logger-factory.js +0 -38
- package/build/common/router-default-logger-factory.js.map +0 -1
- package/build/common/router-handler.d.ts +0 -20
- package/build/common/router-handler.js +0 -154
- package/build/common/router-handler.js.map +0 -1
- package/build/common/router-types.d.ts +0 -63
- package/build/common/router-types.js +0 -86
- package/build/common/router-types.js.map +0 -1
- package/build/common/router-utils.d.ts +0 -3
- package/build/common/router-utils.js +0 -46
- package/build/common/router-utils.js.map +0 -1
- package/build/common/session/common.d.ts +0 -37
- package/build/common/session/common.js +0 -2
- package/build/common/session/common.js.map +0 -1
- package/build/common/session/service.d.ts +0 -26
- package/build/common/session/service.js +0 -154
- package/build/common/session/service.js.map +0 -1
- package/build/common/tokenize-match.d.ts +0 -19
- package/build/common/tokenize-match.js +0 -73
- package/build/common/tokenize-match.js.map +0 -1
- package/build/common/url-utils.d.ts +0 -6
- package/build/common/url-utils.js +0 -48
- package/build/common/url-utils.js.map +0 -1
- package/build/middleware/buffer.d.ts +0 -6
- package/build/middleware/buffer.js +0 -78
- package/build/middleware/buffer.js.map +0 -1
- package/build/middleware/cookie.d.ts +0 -4
- package/build/middleware/cookie.js +0 -15
- package/build/middleware/cookie.js.map +0 -1
- package/build/middleware/cors.d.ts +0 -8
- package/build/middleware/cors.js +0 -89
- package/build/middleware/cors.js.map +0 -1
- package/build/middleware/form.d.ts +0 -6
- package/build/middleware/form.js +0 -58
- package/build/middleware/form.js.map +0 -1
- package/build/middleware/group.d.ts +0 -3
- package/build/middleware/group.js +0 -77
- package/build/middleware/group.js.map +0 -1
- package/build/middleware/json.d.ts +0 -6
- package/build/middleware/json.js +0 -55
- package/build/middleware/json.js.map +0 -1
- package/build/middleware/logger.d.ts +0 -4
- package/build/middleware/logger.js +0 -16
- package/build/middleware/logger.js.map +0 -1
- package/build/middleware/parse.d.ts +0 -14
- package/build/middleware/parse.js +0 -88
- package/build/middleware/parse.js.map +0 -1
- package/build/middleware/result.d.ts +0 -9
- package/build/middleware/result.js +0 -62
- package/build/middleware/result.js.map +0 -1
- package/build/middleware/tag.d.ts +0 -4
- package/build/middleware/tag.js +0 -10
- package/build/middleware/tag.js.map +0 -1
- package/build/middleware/text.d.ts +0 -5
- package/build/middleware/text.js +0 -46
- package/build/middleware/text.js.map +0 -1
- package/build/proxy.d.ts +0 -19
- package/build/proxy.js +0 -74
- package/build/proxy.js.map +0 -1
- package/build/router.d.ts +0 -26
- package/build/router.js +0 -116
- package/build/router.js.map +0 -1
- package/build/static.d.ts +0 -14
- package/build/static.js +0 -211
- package/build/static.js.map +0 -1
- package/build/websocket/cluster.js +0 -114
- package/build/websocket/cluster.js.map +0 -1
- package/build/websocket/server.d.ts +0 -15
- package/build/websocket/server.js +0 -127
- package/build/websocket/server.js.map +0 -1
- package/build/websocket/types.d.ts +0 -39
- package/build/websocket/types.js +0 -2
- package/build/websocket/types.js.map +0 -1
- package/build/websocket/utils.d.ts +0 -8
- package/build/websocket/utils.js +0 -77
- package/build/websocket/utils.js.map +0 -1
- package/src/api-router.ts +0 -50
- package/src/app-utils.ts +0 -82
- package/src/common/api-router-types.ts +0 -52
- package/src/common/api-router-utils.ts +0 -126
- package/src/common/config/config.ts +0 -49
- package/src/common/config/featuretoggle.ts +0 -6
- package/src/common/config/loader.ts +0 -81
- package/src/common/context.ts +0 -192
- package/src/common/error/badrequesterror.ts +0 -6
- package/src/common/error/configfilenotfound.ts +0 -6
- package/src/common/error/forbiddenerror.ts +0 -6
- package/src/common/error/notfound.ts +0 -6
- package/src/common/error/notimplemented.ts +0 -6
- package/src/common/error/unauthorizederror.ts +0 -6
- package/src/common/logger/constants.ts +0 -28
- package/src/common/logger/factory.ts +0 -53
- package/src/common/logger/interfaces.ts +0 -19
- package/src/common/logger/logger.ts +0 -136
- package/src/common/logger/transport/console.ts +0 -36
- package/src/common/logger/transport/file.ts +0 -26
- package/src/common/parser.ts +0 -50
- package/src/common/router-default-logger-factory.ts +0 -44
- package/src/common/router-handler.ts +0 -186
- package/src/common/router-types.ts +0 -153
- package/src/common/router-utils.ts +0 -47
- package/src/common/session/common.ts +0 -40
- package/src/common/session/service.ts +0 -175
- package/src/common/tokenize-match.ts +0 -98
- package/src/common/url-utils.ts +0 -46
- package/src/middleware/buffer.ts +0 -82
- package/src/middleware/cookie.ts +0 -20
- package/src/middleware/cors.ts +0 -98
- package/src/middleware/form.ts +0 -61
- package/src/middleware/group.ts +0 -74
- package/src/middleware/json.ts +0 -57
- package/src/middleware/logger.ts +0 -18
- package/src/middleware/parse.ts +0 -105
- package/src/middleware/result.ts +0 -73
- package/src/middleware/tag.ts +0 -15
- package/src/middleware/text.ts +0 -47
- package/src/proxy.ts +0 -99
- package/src/router.ts +0 -140
- package/src/static.ts +0 -242
- package/src/websocket/cluster.ts +0 -128
- package/src/websocket/server.ts +0 -135
- package/src/websocket/types.ts +0 -41
- package/src/websocket/utils.ts +0 -95
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_PARSER } from "../common/parser.js";
|
|
2
|
-
export const ResultParser = (options, parser) => {
|
|
3
|
-
//options = parse(options, "ParserArgs[]!", undefined, "options");
|
|
4
|
-
const bodyParser = options.body instanceof Array ?
|
|
5
|
-
options.body :
|
|
6
|
-
typeof options.body === "boolean" ?
|
|
7
|
-
options.body === true ?
|
|
8
|
-
[{
|
|
9
|
-
type: "any"
|
|
10
|
-
}] : [] : (typeof options.body === "string" ? [options.body] : options.body ? [options.body] : []);
|
|
11
|
-
const headersParser = options.headers instanceof Array ?
|
|
12
|
-
options.headers :
|
|
13
|
-
typeof options.headers === "boolean" ?
|
|
14
|
-
options.headers === true ?
|
|
15
|
-
[{
|
|
16
|
-
type: "any"
|
|
17
|
-
}] : [] : (typeof options.headers === "string" ? [options.headers] : options.headers ? [options.headers] : []);
|
|
18
|
-
return async function ResultParser(ctx) {
|
|
19
|
-
if (!ctx.results || ctx.results.length === 0) {
|
|
20
|
-
ctx.logger.debug(`not parsing results`);
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
const index = ctx.results.length - 1;
|
|
25
|
-
const lastResult = ctx.results[index] ? ctx.results[index] : undefined;
|
|
26
|
-
ctx.logger.trace(`parsing lastResult.body[%o]`, lastResult);
|
|
27
|
-
try {
|
|
28
|
-
const mappedLastResult = {
|
|
29
|
-
...lastResult
|
|
30
|
-
};
|
|
31
|
-
mappedLastResult.body = parsePart(ctx, "body", lastResult.body, bodyParser, options.bodyMode, parser);
|
|
32
|
-
mappedLastResult.headers = parsePart(ctx, "headers", lastResult.headers, headersParser, options.headersMode, parser);
|
|
33
|
-
return mappedLastResult;
|
|
34
|
-
}
|
|
35
|
-
catch (e) {
|
|
36
|
-
ctx.logger.error(`error parsing lastResult[%o]`, lastResult);
|
|
37
|
-
ctx.logger.error(e);
|
|
38
|
-
throw e;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
function parsePart(ctx, part, value, args, mode, parser) {
|
|
44
|
-
for (let i = 0; i < args.length; i++) {
|
|
45
|
-
const o = args[i];
|
|
46
|
-
try {
|
|
47
|
-
const mappedResultBody = (parser ? parser : DEFAULT_PARSER).parse(value, typeof o === "string" ? o : {
|
|
48
|
-
type: "object",
|
|
49
|
-
properties: o,
|
|
50
|
-
mode
|
|
51
|
-
}, `ctx.results.${part}`);
|
|
52
|
-
ctx.logger.trace(`ctx.results.%s mapped to %o`, part, mappedResultBody);
|
|
53
|
-
return mappedResultBody;
|
|
54
|
-
}
|
|
55
|
-
catch (e) {
|
|
56
|
-
if (i === args.length - 1) {
|
|
57
|
-
throw e;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
//# sourceMappingURL=result.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/middleware/result.ts"],"names":[],"mappings":"A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I,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACpC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,IAAI;YACF,MAAM,gBAAgB,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACnG,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE,CAAC;gBACb,IAAI;aACL,EAAE,eAAe,IAAI,EAAE,CAAC,CAAC;YAC1B,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6B,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC;YACxE,OAAO,gBAAgB,CAAC;SACzB;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;gBACzB,MAAM,CAAC,CAAC;aACT;SACF;KACF;AACH,CAAC"}
|
package/build/middleware/tag.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export const TagResponse = (options) => function TagResponse(ctx) {
|
|
2
|
-
if (options && options.uuid) {
|
|
3
|
-
ctx.setHeader("uuid", ctx.uuid);
|
|
4
|
-
}
|
|
5
|
-
const requestUUID = ctx.headers['request-uuid'];
|
|
6
|
-
if (requestUUID) {
|
|
7
|
-
ctx.setHeader("request-uuid", requestUUID);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=tag.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tag.js","sourceRoot":"","sources":["../../src/middleware/tag.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,OAE3B,EAAiB,EAAE,CAClB,SAAS,WAAW,CAAC,GAAY;IAC/B,IAAI,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE;QAC3B,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;KACjC;IACD,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAChD,IAAI,WAAW,EAAE;QACf,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;KAC5C;AACH,CAAC,CAAC"}
|
package/build/middleware/text.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { checkEnvVariables } from "../common/config/config.js";
|
|
2
|
-
import { BadRequestError } from "../common/error/badrequesterror.js";
|
|
3
|
-
import { DEFAULT_READ_BUFFER_LIMIT, ReadBuffer } from "./buffer.js";
|
|
4
|
-
export const TextParser = (options) => {
|
|
5
|
-
let limit = DEFAULT_READ_BUFFER_LIMIT;
|
|
6
|
-
let type = "plain/text";
|
|
7
|
-
if (options) {
|
|
8
|
-
limit = options.limit !== undefined ? options.limit : limit;
|
|
9
|
-
type = options.type !== undefined ? options.type : type;
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
const [limitS, typeS] = checkEnvVariables(["BODY_TEXT_PARSER_LIMIT", "BODY_TEXT_PARSER_TYPE"], [String(DEFAULT_READ_BUFFER_LIMIT), "plain/text"]);
|
|
13
|
-
limit = parseInt(limitS, 10);
|
|
14
|
-
type = typeS;
|
|
15
|
-
}
|
|
16
|
-
const readBuffer = ReadBuffer({
|
|
17
|
-
limit
|
|
18
|
-
});
|
|
19
|
-
return async function TextParser(ctx) {
|
|
20
|
-
try {
|
|
21
|
-
const isType = ctx.body === undefined && ctx.headers["content-type"] ? ctx.headers["content-type"].toLocaleLowerCase().indexOf(type.toLocaleLowerCase()) !== -1 : false;
|
|
22
|
-
if (isType && !ctx.buffer) {
|
|
23
|
-
await readBuffer(ctx);
|
|
24
|
-
}
|
|
25
|
-
if (isType && ctx.buffer && ctx.buffer.length <= limit) {
|
|
26
|
-
const string = ctx.buffer.toString();
|
|
27
|
-
ctx.logger.debug("ctx.body = %s", string);
|
|
28
|
-
ctx.body = string;
|
|
29
|
-
}
|
|
30
|
-
else if (isType && ctx.buffer && ctx.buffer.length > limit) {
|
|
31
|
-
ctx.logger.error(`ctx.buffer.length ${ctx.buffer.length} > ${limit}. To accept this body set BODY_TEXT_PARSER_LIMIT to a higher value.`);
|
|
32
|
-
throw new BadRequestError(`buffer.length ${ctx.buffer.length} > ${limit}`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
catch (e) {
|
|
36
|
-
if (e && e.name === "BadRequestError") {
|
|
37
|
-
throw e;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
ctx.logger.error(e);
|
|
41
|
-
throw new BadRequestError();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
//# sourceMappingURL=text.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/middleware/text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,yBAAyB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEpE,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAG1B,EAAiB,EAAE;IAClB,IAAI,KAAK,GAAG,yBAAyB,CAAC;IACtC,IAAI,IAAI,GAAG,YAAY,CAAC;IACxB,IAAI,OAAO,EAAE;QACX,KAAK,GAAG,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;QAC5D,IAAI,GAAG,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;KACzD;SAAM;QACL,MAAM,CAAC,MAAM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;gBACzI,MAAM,IAAI,eAAe,CAAC,iBAAiB,GAAG,CAAC,MAAM,CAAC,MAAM,MAAM,KAAK,EAAE,CAAC,CAAC;aAC5E;SACF;QAAC,OAAO,CAAM,EAAE;YACf,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,iBAAiB,EAAE;gBACrC,MAAM,CAAC,CAAC;aACT;iBAAM;gBACL,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBACpB,MAAM,IAAI,eAAe,EAAE,CAAC;aAC7B;SACF;IACH,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
package/build/proxy.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Context } from "./common/context.js";
|
|
2
|
-
import { Router } from "./router.js";
|
|
3
|
-
import { PathPartToken } from "./common/tokenize-match.js";
|
|
4
|
-
import { RouterOptions } from "./common/router-types.js";
|
|
5
|
-
export interface ProxyRouterOptions extends RouterOptions {
|
|
6
|
-
url: string;
|
|
7
|
-
rejectUnauthorized?: boolean;
|
|
8
|
-
}
|
|
9
|
-
declare class ProxyRouter extends Router {
|
|
10
|
-
private readonly proxyURL;
|
|
11
|
-
private readonly rejectUnauthorized?;
|
|
12
|
-
constructor(options: ProxyRouterOptions);
|
|
13
|
-
run(ctx: Context, pathTokens?: {
|
|
14
|
-
value: string;
|
|
15
|
-
lower: string;
|
|
16
|
-
}[], prePathTokens?: PathPartToken[]): Promise<boolean>;
|
|
17
|
-
}
|
|
18
|
-
export declare const Proxy: (options: ProxyRouterOptions) => ProxyRouter;
|
|
19
|
-
export {};
|
package/build/proxy.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { request } from "@miqro/request";
|
|
2
|
-
import { Router } from "./router.js";
|
|
3
|
-
import { normalizePath } from "./common/url-utils.js";
|
|
4
|
-
import { URL } from "url";
|
|
5
|
-
class ProxyRouter extends Router {
|
|
6
|
-
constructor(options) {
|
|
7
|
-
super(options);
|
|
8
|
-
const proxyURL = new URL(options.url);
|
|
9
|
-
proxyURL.pathname = normalizePath(proxyURL.pathname);
|
|
10
|
-
this.proxyURL = proxyURL;
|
|
11
|
-
this.rejectUnauthorized = options.rejectUnauthorized;
|
|
12
|
-
}
|
|
13
|
-
async run(ctx, pathTokens, prePathTokens = []) {
|
|
14
|
-
const level = prePathTokens.length;
|
|
15
|
-
const shouldContinue = await super.run(ctx, pathTokens, prePathTokens);
|
|
16
|
-
if (shouldContinue) {
|
|
17
|
-
const relative = ctx.path.split("/").map(s => s.trim()).filter(s => s).slice(level).join("/");
|
|
18
|
-
const nUrl = new URL(this.proxyURL.toString());
|
|
19
|
-
nUrl.pathname = nUrl.pathname + relative;
|
|
20
|
-
const url = nUrl.toString();
|
|
21
|
-
const headers = {
|
|
22
|
-
...ctx.headers
|
|
23
|
-
};
|
|
24
|
-
delete headers["connection"];
|
|
25
|
-
delete headers["keep-alive"];
|
|
26
|
-
let responseHeaders;
|
|
27
|
-
const requestArgs = {
|
|
28
|
-
url: url.toString(),
|
|
29
|
-
query: ctx.query,
|
|
30
|
-
disableThrow: true,
|
|
31
|
-
rejectUnauthorized: this.rejectUnauthorized,
|
|
32
|
-
disableUserAgent: true,
|
|
33
|
-
method: ctx.method,
|
|
34
|
-
headers,
|
|
35
|
-
onChunk: async function (chunk, res) {
|
|
36
|
-
const responseHeaders = {
|
|
37
|
-
...res.headers
|
|
38
|
-
};
|
|
39
|
-
delete responseHeaders["connection"];
|
|
40
|
-
delete responseHeaders["keep-alive"];
|
|
41
|
-
if (!ctx.res.headersSent) {
|
|
42
|
-
const headerNames = Object.keys(responseHeaders);
|
|
43
|
-
for (const name of headerNames) {
|
|
44
|
-
ctx.setHeader(name, responseHeaders[name]);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (res.statusCode !== undefined) {
|
|
48
|
-
ctx.res.statusCode = res.statusCode;
|
|
49
|
-
}
|
|
50
|
-
await ctx.write(chunk);
|
|
51
|
-
},
|
|
52
|
-
data: ctx.method !== "GET" ? ctx.buffer : undefined
|
|
53
|
-
};
|
|
54
|
-
ctx.logger.info("proxy to %s", url.toString());
|
|
55
|
-
ctx.logger.debug("proxy with %o", requestArgs);
|
|
56
|
-
const response = await request(requestArgs);
|
|
57
|
-
if (!ctx.res.headersSent) {
|
|
58
|
-
const responseHeaders = {
|
|
59
|
-
...response.headers
|
|
60
|
-
};
|
|
61
|
-
const headerNames = Object.keys(responseHeaders);
|
|
62
|
-
for (const name of headerNames) {
|
|
63
|
-
ctx.setHeader(name, responseHeaders[name]);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
await ctx.end();
|
|
67
|
-
}
|
|
68
|
-
return !ctx.res.headersSent;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
export const Proxy = (options) => {
|
|
72
|
-
return new ProxyRouter(options);
|
|
73
|
-
};
|
|
74
|
-
//# sourceMappingURL=proxy.js.map
|
package/build/proxy.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAkB,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAS1B,MAAM,WAAY,SAAQ,MAAM;IAI9B,YAAY,OAA2B;QACrC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACtC,QAAQ,CAAC,QAAQ,GAAG,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACrD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC;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,IAAI,CAAQ,CAAC,CAAC;iBACnD;aACF;YAED,MAAM,GAAG,CAAC,GAAG,EAAE,CAAC;SACjB;QACD,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC;IAC9B,CAAC;CACF;AAED,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,OAA2B,EAAE,EAAE;IACnD,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;AAClC,CAAC,CAAA"}
|
package/build/router.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import { RequestListener } from "http";
|
|
3
|
-
import { Logger } from "./common/logger/logger.js";
|
|
4
|
-
import { Context, ErrorHandler, Handler, Method } from "./common/context.js";
|
|
5
|
-
import { HandlerWithOptions, MinimalRouter, RouterHandlerOptions, RouterJSONDoc, RouterOptions } from "./common/router-types.js";
|
|
6
|
-
import { PathPart, PathPartToken } from "./common/tokenize-match.js";
|
|
7
|
-
import { RouterHandler } from "./common/router-handler.js";
|
|
8
|
-
export declare class Router implements MinimalRouter {
|
|
9
|
-
protected config?: RouterOptions | undefined;
|
|
10
|
-
protected readonly handlers: RouterHandler[];
|
|
11
|
-
protected readonly errorHandlers: ErrorHandler[];
|
|
12
|
-
readonly listener: RequestListener;
|
|
13
|
-
constructor(config?: RouterOptions | undefined);
|
|
14
|
-
get(path: string | undefined, handler: Array<Handler> | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router;
|
|
15
|
-
post(path: string | undefined, handler: Array<Handler> | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router;
|
|
16
|
-
patch(path: string | undefined, handler: Array<Handler> | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router;
|
|
17
|
-
delete(path: string | undefined, handler: Array<Handler> | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router;
|
|
18
|
-
put(path: string | undefined, handler: Array<Handler> | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router;
|
|
19
|
-
options(path: string | undefined, handler: Array<Handler> | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router;
|
|
20
|
-
use(handler: Array<Handler> | HandlerWithOptions | Handler | MinimalRouter, path?: string, method?: Method, options?: RouterHandlerOptions): Router;
|
|
21
|
-
catch(errorHandler: Array<ErrorHandler> | ErrorHandler): Router;
|
|
22
|
-
run(ctx: Context, pathTokens?: PathPart[], prePathTokens?: PathPartToken[]): Promise<boolean>;
|
|
23
|
-
getJSONDoc(doc?: RouterJSONDoc, prePath?: string): RouterJSONDoc;
|
|
24
|
-
logPaths(logger: Logger): void;
|
|
25
|
-
toString(): string;
|
|
26
|
-
}
|
package/build/router.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { Context } from "./common/context.js";
|
|
2
|
-
import { splitPath } from "./common/tokenize-match.js";
|
|
3
|
-
import { defaultLoggerFactory } from "./common/router-default-logger-factory.js";
|
|
4
|
-
import { RouterHandler } from "./common/router-handler.js";
|
|
5
|
-
import { randomUUID } from "crypto";
|
|
6
|
-
import { normalizePath } from "./common/url-utils.js";
|
|
7
|
-
export class Router {
|
|
8
|
-
constructor(config) {
|
|
9
|
-
this.config = config;
|
|
10
|
-
this.handlers = [];
|
|
11
|
-
this.errorHandlers = [];
|
|
12
|
-
const loggerFactory = this.config && this.config.loggerFactory ? this.config.loggerFactory : defaultLoggerFactory;
|
|
13
|
-
this.listener = async (req, res) => {
|
|
14
|
-
const uuid = randomUUID();
|
|
15
|
-
const logger = loggerFactory(uuid, req);
|
|
16
|
-
const ctx = new Context(uuid, req, res, logger);
|
|
17
|
-
ctx.logger.trace(`request received`);
|
|
18
|
-
await this.run(ctx);
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
get(path, handler, options) {
|
|
22
|
-
return this.use(handler, path, "get", options);
|
|
23
|
-
}
|
|
24
|
-
post(path, handler, options) {
|
|
25
|
-
return this.use(handler, path, "post", options);
|
|
26
|
-
}
|
|
27
|
-
patch(path, handler, options) {
|
|
28
|
-
return this.use(handler, path, "patch", options);
|
|
29
|
-
}
|
|
30
|
-
delete(path, handler, options) {
|
|
31
|
-
return this.use(handler, path, "delete", options);
|
|
32
|
-
}
|
|
33
|
-
put(path, handler, options) {
|
|
34
|
-
return this.use(handler, path, "put", options);
|
|
35
|
-
}
|
|
36
|
-
options(path, handler, options) {
|
|
37
|
-
return this.use(handler, path, "options", options);
|
|
38
|
-
}
|
|
39
|
-
use(handler, path, method, options) {
|
|
40
|
-
const nPath = path !== undefined ? normalizePath(path) : undefined;
|
|
41
|
-
const nMethod = method ? method.toUpperCase() : method;
|
|
42
|
-
this.handlers.push(new RouterHandler(handler, nPath, nMethod, options));
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
catch(errorHandler) {
|
|
46
|
-
const errorHandlers = errorHandler instanceof Array ? errorHandler : [errorHandler];
|
|
47
|
-
for (const e of errorHandlers) {
|
|
48
|
-
if (typeof e !== "function") {
|
|
49
|
-
throw new Error(`errorHandler ${e} not a function!`);
|
|
50
|
-
}
|
|
51
|
-
this.errorHandlers.push(e);
|
|
52
|
-
}
|
|
53
|
-
return this;
|
|
54
|
-
}
|
|
55
|
-
async run(ctx, pathTokens, prePathTokens = []) {
|
|
56
|
-
pathTokens = pathTokens ? pathTokens : splitPath(ctx.path);
|
|
57
|
-
try {
|
|
58
|
-
for (const h of this.handlers) {
|
|
59
|
-
if (ctx.res.headersSent) {
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
const isMatch = h.isMatch(ctx.method, pathTokens, prePathTokens);
|
|
63
|
-
if (isMatch.match) {
|
|
64
|
-
if (isMatch.params) {
|
|
65
|
-
ctx.params = ctx.params ? {
|
|
66
|
-
...ctx.params,
|
|
67
|
-
...isMatch.params
|
|
68
|
-
} : isMatch.params;
|
|
69
|
-
}
|
|
70
|
-
const shouldContinue = await h.invoke(ctx, pathTokens, prePathTokens);
|
|
71
|
-
if (!shouldContinue) {
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return !ctx.res.headersSent;
|
|
77
|
-
}
|
|
78
|
-
catch (e) {
|
|
79
|
-
for (const eH of this.errorHandlers) {
|
|
80
|
-
const ret = await eH(e, ctx);
|
|
81
|
-
if (ret === false || ctx.res.headersSent) {
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
throw e; // pass the error along
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
getJSONDoc(doc = {}, prePath = "/") {
|
|
89
|
-
for (const h of this.handlers) {
|
|
90
|
-
doc = h.getJSONDoc(doc, prePath);
|
|
91
|
-
}
|
|
92
|
-
return doc;
|
|
93
|
-
}
|
|
94
|
-
logPaths(logger) {
|
|
95
|
-
this.toString().split("\n").forEach(l => logger.info(l));
|
|
96
|
-
}
|
|
97
|
-
toString() {
|
|
98
|
-
let ret = "";
|
|
99
|
-
const doc = this.getJSONDoc();
|
|
100
|
-
const paths = Object.keys(doc);
|
|
101
|
-
for (const path of paths) {
|
|
102
|
-
if (path) {
|
|
103
|
-
const pathData = doc[path];
|
|
104
|
-
const methods = Object.keys(pathData);
|
|
105
|
-
for (const method of methods) {
|
|
106
|
-
if (method) {
|
|
107
|
-
const methodData = pathData[method];
|
|
108
|
-
ret += `${ret === "" ? "" : "\n"}${method}:${path}\n\t${methodData.identifier}${methodData.name ? `\n\t\t${methodData.name}` : ""}${methodData.description ? `\n\t\t${methodData.description}` : ""}`;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return ret;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
//# sourceMappingURL=router.js.map
|
package/build/router.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAE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I,GAAG,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,MAAM,IAAI,IAAI,OAAO,UAAU,CAAC,UAAU,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;qBACvM;iBACF;aACF;SACF;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF"}
|
package/build/static.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Router } from "./router.js";
|
|
2
|
-
import { RouterOptions } from "./common/router-types.js";
|
|
3
|
-
export interface StaticRouterOptions extends RouterOptions {
|
|
4
|
-
directory: string;
|
|
5
|
-
list?: boolean;
|
|
6
|
-
allowListJSON?: boolean;
|
|
7
|
-
allowGetJSON?: boolean;
|
|
8
|
-
index?: string;
|
|
9
|
-
index404?: string;
|
|
10
|
-
index404Status?: number;
|
|
11
|
-
contentTypes?: any;
|
|
12
|
-
defaultContentType?: string;
|
|
13
|
-
}
|
|
14
|
-
export declare function Static(options: StaticRouterOptions): Router;
|
package/build/static.js
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import { existsSync, readdirSync, readFileSync, statSync } from "fs";
|
|
2
|
-
import { extname, resolve } from "path";
|
|
3
|
-
import { Router } from "./router.js";
|
|
4
|
-
import { assertNotUndefined, DEFAULT_PARSER } from "./common/parser.js";
|
|
5
|
-
const outputFile = async (path, contentType, ctx, allowGetJSON, status = 200) => {
|
|
6
|
-
const buffer = readFileSync(path);
|
|
7
|
-
return allowGetJSON && ctx.query.format && ctx.query.format === "json" ?
|
|
8
|
-
ctx.json({
|
|
9
|
-
buffer
|
|
10
|
-
}) :
|
|
11
|
-
ctx.end({
|
|
12
|
-
status,
|
|
13
|
-
headers: {
|
|
14
|
-
["Content-Type"]: contentType
|
|
15
|
-
},
|
|
16
|
-
body: buffer
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
const generateList = async (path, ctx, allowListJSON) => {
|
|
20
|
-
const files = readdirSync(path);
|
|
21
|
-
return allowListJSON && ctx.query.format && ctx.query.format === "json" ?
|
|
22
|
-
ctx.json({ files: files.map(f => `${ctx.path}${f}`) }) :
|
|
23
|
-
ctx.html(`<html><body><ul>${files.map(f => `<li><a href="${ctx.path}${f}">${f}</a></li>`).join("")}</ul></body></html>`);
|
|
24
|
-
};
|
|
25
|
-
export function Static(options) {
|
|
26
|
-
return new StaticRouter(options);
|
|
27
|
-
}
|
|
28
|
-
class StaticRouter extends Router {
|
|
29
|
-
constructor(options) {
|
|
30
|
-
super(options);
|
|
31
|
-
this.staticOptions = assertNotUndefined(DEFAULT_PARSER.parse(options, {
|
|
32
|
-
type: "object",
|
|
33
|
-
properties: {
|
|
34
|
-
loggerFactory: {
|
|
35
|
-
required: false,
|
|
36
|
-
type: "any"
|
|
37
|
-
},
|
|
38
|
-
directory: {
|
|
39
|
-
type: "string",
|
|
40
|
-
required: true
|
|
41
|
-
},
|
|
42
|
-
list: {
|
|
43
|
-
type: "boolean",
|
|
44
|
-
required: false,
|
|
45
|
-
defaultValue: false
|
|
46
|
-
},
|
|
47
|
-
allowListJSON: {
|
|
48
|
-
type: "boolean",
|
|
49
|
-
required: false,
|
|
50
|
-
defaultValue: false
|
|
51
|
-
},
|
|
52
|
-
allowGetJSON: {
|
|
53
|
-
type: "boolean",
|
|
54
|
-
required: false,
|
|
55
|
-
defaultValue: false
|
|
56
|
-
},
|
|
57
|
-
index: {
|
|
58
|
-
type: "string",
|
|
59
|
-
required: false,
|
|
60
|
-
defaultValue: "index.html"
|
|
61
|
-
},
|
|
62
|
-
index404: {
|
|
63
|
-
type: "string",
|
|
64
|
-
required: false
|
|
65
|
-
},
|
|
66
|
-
index404Status: {
|
|
67
|
-
type: "number",
|
|
68
|
-
required: false,
|
|
69
|
-
defaultValue: 404
|
|
70
|
-
},
|
|
71
|
-
contentTypes: {
|
|
72
|
-
type: "object",
|
|
73
|
-
required: false,
|
|
74
|
-
defaultValue: {
|
|
75
|
-
".aac": "audio/aac",
|
|
76
|
-
".abw": "application/x-abiword",
|
|
77
|
-
".arc": "application/x-freearc",
|
|
78
|
-
".avif": "image/avif",
|
|
79
|
-
".avi": "video/x-msvideo",
|
|
80
|
-
".azw": "application/vnd.amazon.ebook",
|
|
81
|
-
".bin": "application/octet-stream",
|
|
82
|
-
".bmp": "image/bmp",
|
|
83
|
-
".bz": "application/x-bzip",
|
|
84
|
-
".bz2": "application/x-bzip2",
|
|
85
|
-
".cda": "application/x-cdf",
|
|
86
|
-
".csh": "application/x-csh",
|
|
87
|
-
".css": "text/css",
|
|
88
|
-
".csv": "text/csv",
|
|
89
|
-
".doc": "application/msword",
|
|
90
|
-
".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
91
|
-
".eot": "application/vnd.ms-fontobject",
|
|
92
|
-
".epub": "application/epub+zip",
|
|
93
|
-
".gz": "application/gzip",
|
|
94
|
-
".gif": "image/gif",
|
|
95
|
-
".htm": "text/html",
|
|
96
|
-
".html": "text/html",
|
|
97
|
-
".ico": "image/vnd.microsoft.icon",
|
|
98
|
-
".ics": "text/calendar",
|
|
99
|
-
".jar": "application/java-archive",
|
|
100
|
-
".jpeg": "image/jpeg",
|
|
101
|
-
".jpg": "image/jpeg",
|
|
102
|
-
".js": "text/javascript",
|
|
103
|
-
".json": "application/json",
|
|
104
|
-
".jsonld": "application/ld+json",
|
|
105
|
-
".mid": "audio/midi audio/x-midi",
|
|
106
|
-
".midi": "audio/midi audio/x-midi",
|
|
107
|
-
".mjs": "text/javascript",
|
|
108
|
-
".mp3": "audio/mpeg",
|
|
109
|
-
".mp4": "video/mp4",
|
|
110
|
-
".mpeg": "video/mpeg",
|
|
111
|
-
".mpkg": "application/vnd.apple.installer+xml",
|
|
112
|
-
".odp": "application/vnd.oasis.opendocument.presentation",
|
|
113
|
-
".ods": "application/vnd.oasis.opendocument.spreadsheet",
|
|
114
|
-
".odt": "application/vnd.oasis.opendocument.text",
|
|
115
|
-
".oga": "audio/ogg",
|
|
116
|
-
".ogv": "video/ogg",
|
|
117
|
-
".ogx": "application/ogg",
|
|
118
|
-
".opus": "audio/opus",
|
|
119
|
-
".otf": "font/otf",
|
|
120
|
-
".png": "image/png",
|
|
121
|
-
".pdf": "application/pdf",
|
|
122
|
-
".php": "application/x-httpd-php",
|
|
123
|
-
".ppt": "application/vnd.ms-powerpoint",
|
|
124
|
-
".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
125
|
-
".rar": "application/vnd.rar",
|
|
126
|
-
".rtf": "application/rtf",
|
|
127
|
-
".sh": "application/x-sh",
|
|
128
|
-
".svg": "image/svg+xml",
|
|
129
|
-
".swf": "application/x-shockwave-flash",
|
|
130
|
-
".tar": "application/x-tar",
|
|
131
|
-
".tif": "image/tiff",
|
|
132
|
-
".tiff": "image/tiff",
|
|
133
|
-
".ts": "video/mp2t",
|
|
134
|
-
".ttf": "font/ttf",
|
|
135
|
-
".txt": "text/plain",
|
|
136
|
-
".vsd": "application/vnd.visio",
|
|
137
|
-
".wav": "audio/wav",
|
|
138
|
-
".weba": "audio/webm",
|
|
139
|
-
".webm": "video/webm",
|
|
140
|
-
".webp": "image/webp",
|
|
141
|
-
".woff": "font/woff",
|
|
142
|
-
".woff2": "font/woff2",
|
|
143
|
-
".xhtml": "application/xhtml+xml",
|
|
144
|
-
".xls": "application/vnd.ms-excel",
|
|
145
|
-
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
146
|
-
".xml": "application/xml",
|
|
147
|
-
".xul": "application/vnd.mozilla.xul+xml",
|
|
148
|
-
".zip": "application/zip",
|
|
149
|
-
".3gp": "video/3gpp; audio/3gpp",
|
|
150
|
-
".3g2": "video/3gpp2; audio/3gpp2",
|
|
151
|
-
".7z": "application/x-7z-compressed"
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
defaultContentType: {
|
|
155
|
-
type: "string",
|
|
156
|
-
required: false,
|
|
157
|
-
defaultValue: "application/octet-stream"
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}, "options"), "bad options");
|
|
161
|
-
if (!statSync(this.staticOptions.directory).isDirectory()) {
|
|
162
|
-
throw new Error(`options.directory ${this.staticOptions.directory} not a directory`);
|
|
163
|
-
}
|
|
164
|
-
if (this.staticOptions.index404 && !existsSync(resolve(this.staticOptions.directory, this.staticOptions.index404))) {
|
|
165
|
-
throw new Error(`options.index404 ${this.staticOptions.index404} not a found`);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
async run(ctx, pathTokens, prePathTokens = []) {
|
|
169
|
-
const { directory, allowGetJSON, allowListJSON, list, index, contentTypes, defaultContentType } = this.staticOptions;
|
|
170
|
-
const level = prePathTokens.length;
|
|
171
|
-
if (ctx.method === "GET") {
|
|
172
|
-
const realPath = resolve(directory, ctx.path.split("/").map(s => s.trim()).filter(s => s).slice(level).join("/"));
|
|
173
|
-
ctx.logger.debug("static get %s", realPath);
|
|
174
|
-
if (existsSync(realPath)) {
|
|
175
|
-
if (statSync(realPath).isDirectory()) {
|
|
176
|
-
// directory
|
|
177
|
-
const indexPath = resolve(realPath, index);
|
|
178
|
-
if (index && existsSync(indexPath) && statSync(indexPath).isFile()) {
|
|
179
|
-
// index file exists
|
|
180
|
-
const ext = extname(indexPath);
|
|
181
|
-
const contentType = contentTypes[ext] ? contentTypes[ext] : defaultContentType;
|
|
182
|
-
await outputFile(indexPath, contentType, ctx, allowGetJSON);
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
// index doesn't exists
|
|
186
|
-
if (list) {
|
|
187
|
-
// generate list
|
|
188
|
-
await generateList(realPath, ctx, allowListJSON);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
// direct file access
|
|
194
|
-
const ext = extname(realPath);
|
|
195
|
-
const contentType = contentTypes[ext] ? contentTypes[ext] : defaultContentType;
|
|
196
|
-
await outputFile(realPath, contentType, ctx, allowGetJSON);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
if (this.staticOptions.index404) {
|
|
201
|
-
const realPath = resolve(this.staticOptions.directory, this.staticOptions.index404);
|
|
202
|
-
if (existsSync(realPath)) {
|
|
203
|
-
const ext = extname(realPath);
|
|
204
|
-
const contentType = contentTypes[ext] ? contentTypes[ext] : defaultContentType;
|
|
205
|
-
await outputFile(realPath, contentType, ctx, allowGetJSON, this.staticOptions.index404Status);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return !ctx.res.headersSent ? super.run(ctx, pathTokens, prePathTokens) : false;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
//# sourceMappingURL=static.js.map
|