@lwrjs/server 0.6.5 → 0.7.0-alpha.10
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/LICENSE +10 -0
- package/build/cjs/common/compression.cjs +45 -0
- package/build/cjs/express/express-request.cjs +6 -2
- package/build/cjs/express/express-server.cjs +2 -2
- package/build/cjs/koa/koa-request.cjs +6 -2
- package/build/es/common/compression.d.ts +3 -0
- package/build/es/common/compression.js +25 -0
- package/build/es/express/express-request.d.ts +2 -1
- package/build/es/express/express-request.js +5 -1
- package/build/es/express/express-server.js +2 -5
- package/build/es/koa/koa-request.d.ts +2 -1
- package/build/es/koa/koa-request.js +5 -1
- package/package.json +10 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
MIT LICENSE
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020, Salesforce.com, Inc.
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
7
|
+
|
|
8
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
9
|
+
|
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
11
|
+
};
|
|
12
|
+
var __exportStar = (target, module2, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
+
__defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toModule = (module2) => {
|
|
21
|
+
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// packages/@lwrjs/server/src/common/compression.ts
|
|
25
|
+
__markAsModule(exports);
|
|
26
|
+
__export(exports, {
|
|
27
|
+
default: () => compression_default
|
|
28
|
+
});
|
|
29
|
+
var import_compression = __toModule(require("compression"));
|
|
30
|
+
var compressionLibToUse;
|
|
31
|
+
var compression = async (req, res, next) => {
|
|
32
|
+
if (compressionLibToUse === void 0) {
|
|
33
|
+
try {
|
|
34
|
+
let shrinkRay = await Promise.resolve().then(() => __toModule(require("shrink-ray-current")));
|
|
35
|
+
shrinkRay = shrinkRay.default || shrinkRay;
|
|
36
|
+
compressionLibToUse = shrinkRay({useZopfliForGzip: false});
|
|
37
|
+
} catch (err) {
|
|
38
|
+
compressionLibToUse = (0, import_compression.default)();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
compressionLibToUse(req, res, next);
|
|
42
|
+
};
|
|
43
|
+
function compression_default() {
|
|
44
|
+
return compression;
|
|
45
|
+
}
|
|
@@ -33,6 +33,9 @@ var ExpressRequest = class {
|
|
|
33
33
|
get method() {
|
|
34
34
|
return this.req.method;
|
|
35
35
|
}
|
|
36
|
+
get headers() {
|
|
37
|
+
return this.req.headers;
|
|
38
|
+
}
|
|
36
39
|
get protocol() {
|
|
37
40
|
return this.req.protocol;
|
|
38
41
|
}
|
|
@@ -68,7 +71,7 @@ var ExpressRequest = class {
|
|
|
68
71
|
return !this.hasJsonParam() || this.req.accepts("json") === "json";
|
|
69
72
|
}
|
|
70
73
|
getRuntimeContext(defaultRuntimeEnvironment) {
|
|
71
|
-
const {format, apiVersion, compat, locale, environment} = this.req.params;
|
|
74
|
+
const {format, apiVersion, compat, locale, environment, bundleSpecifier} = this.req.params;
|
|
72
75
|
const {debug} = this.req.query;
|
|
73
76
|
return {
|
|
74
77
|
runtimeEnvironment: {
|
|
@@ -76,7 +79,8 @@ var ExpressRequest = class {
|
|
|
76
79
|
format: format ? format : defaultRuntimeEnvironment.format,
|
|
77
80
|
compat: compat !== void 0 ? compat : defaultRuntimeEnvironment.compat,
|
|
78
81
|
debug: debug !== void 0 ? true : defaultRuntimeEnvironment.debug,
|
|
79
|
-
apiVersion: apiVersion ? apiVersion : defaultRuntimeEnvironment.apiVersion
|
|
82
|
+
apiVersion: apiVersion ? apiVersion : defaultRuntimeEnvironment.apiVersion,
|
|
83
|
+
bundle: bundleSpecifier !== void 0 ? true : false
|
|
80
84
|
},
|
|
81
85
|
runtimeParams: {
|
|
82
86
|
locale: locale ? locale : this.req.locale ? this.req.locale : defaultRuntimeEnvironment.defaultLocale,
|
|
@@ -29,7 +29,7 @@ __export(exports, {
|
|
|
29
29
|
var import_express = __toModule(require("express"));
|
|
30
30
|
var import_spdy = __toModule(require("spdy"));
|
|
31
31
|
var import_http = __toModule(require("http"));
|
|
32
|
-
var
|
|
32
|
+
var import_compression = __toModule(require("../common/compression.cjs"));
|
|
33
33
|
var import_abstract_internal_app_server = __toModule(require("../common/abstract-internal-app-server.cjs"));
|
|
34
34
|
var import_express_request = __toModule(require("./express-request.cjs"));
|
|
35
35
|
var import_express_response = __toModule(require("./express-response.cjs"));
|
|
@@ -91,7 +91,7 @@ var ExpressInternalServer = class extends import_abstract_internal_app_server.de
|
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
93
|
useCompression() {
|
|
94
|
-
this.expressApp.use((0,
|
|
94
|
+
this.expressApp.use((0, import_compression.default)());
|
|
95
95
|
}
|
|
96
96
|
getRegexWildcard() {
|
|
97
97
|
return "*";
|
|
@@ -36,6 +36,9 @@ var KoaRequest = class {
|
|
|
36
36
|
get method() {
|
|
37
37
|
return this.ctx.method;
|
|
38
38
|
}
|
|
39
|
+
get headers() {
|
|
40
|
+
return this.ctx.headers;
|
|
41
|
+
}
|
|
39
42
|
get locale() {
|
|
40
43
|
return this.ctx.locale;
|
|
41
44
|
}
|
|
@@ -66,7 +69,7 @@ var KoaRequest = class {
|
|
|
66
69
|
return !this.hasJsonParam() || this.ctx.request.accepts("json") === "json";
|
|
67
70
|
}
|
|
68
71
|
getRuntimeContext(defaultRuntimeEnvironment) {
|
|
69
|
-
const {format, apiVersion, compat, locale, environment} = this.params;
|
|
72
|
+
const {format, apiVersion, compat, locale, environment, bundleSpecifier} = this.params;
|
|
70
73
|
const {debug} = this.ctx.request.query;
|
|
71
74
|
return {
|
|
72
75
|
runtimeEnvironment: {
|
|
@@ -74,7 +77,8 @@ var KoaRequest = class {
|
|
|
74
77
|
format: format ? format : defaultRuntimeEnvironment.format,
|
|
75
78
|
compat: compat !== void 0 ? compat : defaultRuntimeEnvironment.compat,
|
|
76
79
|
debug: debug !== void 0 ? true : defaultRuntimeEnvironment.debug,
|
|
77
|
-
apiVersion: apiVersion ? apiVersion : defaultRuntimeEnvironment.apiVersion
|
|
80
|
+
apiVersion: apiVersion ? apiVersion : defaultRuntimeEnvironment.apiVersion,
|
|
81
|
+
bundle: bundleSpecifier !== void 0 ? true : false
|
|
78
82
|
},
|
|
79
83
|
runtimeParams: {
|
|
80
84
|
locale: locale ? locale : this.ctx.locale ? this.ctx.locale : defaultRuntimeEnvironment.defaultLocale,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import expressCompression from 'compression';
|
|
2
|
+
let compressionLibToUse;
|
|
3
|
+
const compression = async (req, res, next) => {
|
|
4
|
+
if (compressionLibToUse === undefined) {
|
|
5
|
+
// TODO: Unfortunately the compression story for express is a mess.
|
|
6
|
+
// shrink-ray-current is a fork of compression with brotlli support, we will use it until the
|
|
7
|
+
// "official" one accepts a PR to support it: https://github.com/expressjs/compression/issues/71
|
|
8
|
+
// Since it has some native dependencies (node-zopfli-es, iltorb) that may fail to compile in
|
|
9
|
+
// certain environments, we make it an optional dependency and fall back to vanilla compression.
|
|
10
|
+
try {
|
|
11
|
+
let shrinkRay = await import('shrink-ray-current');
|
|
12
|
+
shrinkRay = shrinkRay.default || shrinkRay;
|
|
13
|
+
compressionLibToUse = shrinkRay({ useZopfliForGzip: false });
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
compressionLibToUse = expressCompression();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
20
|
+
compressionLibToUse(req, res, next);
|
|
21
|
+
};
|
|
22
|
+
export default function () {
|
|
23
|
+
return compression;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=compression.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Request } from 'express';
|
|
2
|
-
import { RuntimeContext, RuntimeEnvironment, MiddlewareRequest } from '@lwrjs/types';
|
|
2
|
+
import { RuntimeContext, RuntimeEnvironment, MiddlewareRequest, Headers } from '@lwrjs/types';
|
|
3
3
|
export default class ExpressRequest implements MiddlewareRequest {
|
|
4
4
|
private req;
|
|
5
5
|
isMetadataRequest: boolean;
|
|
@@ -10,6 +10,7 @@ export default class ExpressRequest implements MiddlewareRequest {
|
|
|
10
10
|
get query(): any;
|
|
11
11
|
get body(): any;
|
|
12
12
|
get method(): string;
|
|
13
|
+
get headers(): Headers;
|
|
13
14
|
get protocol(): any;
|
|
14
15
|
get locale(): string;
|
|
15
16
|
set locale(l: string);
|
|
@@ -22,6 +22,9 @@ export default class ExpressRequest {
|
|
|
22
22
|
get method() {
|
|
23
23
|
return this.req.method;
|
|
24
24
|
}
|
|
25
|
+
get headers() {
|
|
26
|
+
return this.req.headers;
|
|
27
|
+
}
|
|
25
28
|
get protocol() {
|
|
26
29
|
return this.req.protocol;
|
|
27
30
|
}
|
|
@@ -58,7 +61,7 @@ export default class ExpressRequest {
|
|
|
58
61
|
return !this.hasJsonParam() || this.req.accepts('json') === 'json';
|
|
59
62
|
}
|
|
60
63
|
getRuntimeContext(defaultRuntimeEnvironment) {
|
|
61
|
-
const { format, apiVersion, compat, locale, environment } = this.req.params;
|
|
64
|
+
const { format, apiVersion, compat, locale, environment, bundleSpecifier } = this.req.params;
|
|
62
65
|
const { debug } = this.req.query;
|
|
63
66
|
return {
|
|
64
67
|
runtimeEnvironment: {
|
|
@@ -67,6 +70,7 @@ export default class ExpressRequest {
|
|
|
67
70
|
compat: compat !== undefined ? compat : defaultRuntimeEnvironment.compat,
|
|
68
71
|
debug: debug !== undefined ? true : defaultRuntimeEnvironment.debug,
|
|
69
72
|
apiVersion: apiVersion ? apiVersion : defaultRuntimeEnvironment.apiVersion,
|
|
73
|
+
bundle: bundleSpecifier !== undefined ? true : false, // the absence of a bundle strategy means bundling is off
|
|
70
74
|
},
|
|
71
75
|
runtimeParams: {
|
|
72
76
|
locale: locale
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import spdy from 'spdy';
|
|
3
3
|
import http from 'http';
|
|
4
|
-
import compression from '
|
|
4
|
+
import compression from '../common/compression.js';
|
|
5
5
|
import AbstractInternalAppServer from '../common/abstract-internal-app-server.js';
|
|
6
6
|
import ExpressRequest from './express-request.js';
|
|
7
7
|
import ExpressResponse from './express-response.js';
|
|
@@ -68,10 +68,7 @@ export default class ExpressInternalServer extends AbstractInternalAppServer {
|
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
useCompression() {
|
|
71
|
-
|
|
72
|
-
// shrink-ray is a fork of compression with brotlli support, we will use it
|
|
73
|
-
// until the "official" one accepts a PR to support it
|
|
74
|
-
this.expressApp.use(compression({ useZopfliForGzip: false }));
|
|
71
|
+
this.expressApp.use(compression());
|
|
75
72
|
}
|
|
76
73
|
getRegexWildcard() {
|
|
77
74
|
return '*';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Koa from 'koa';
|
|
2
|
-
import { RuntimeContext, RuntimeEnvironment, MiddlewareRequest } from '@lwrjs/types';
|
|
2
|
+
import { RuntimeContext, RuntimeEnvironment, MiddlewareRequest, Headers } from '@lwrjs/types';
|
|
3
3
|
export default class KoaRequest implements MiddlewareRequest {
|
|
4
4
|
protected ctx: Koa.Context;
|
|
5
5
|
isMetadataRequest: boolean;
|
|
@@ -11,6 +11,7 @@ export default class KoaRequest implements MiddlewareRequest {
|
|
|
11
11
|
get protocol(): any;
|
|
12
12
|
get body(): any;
|
|
13
13
|
get method(): string;
|
|
14
|
+
get headers(): Headers;
|
|
14
15
|
get locale(): string;
|
|
15
16
|
set locale(l: string);
|
|
16
17
|
isSiteGeneration(): boolean;
|
|
@@ -24,6 +24,9 @@ export default class KoaRequest {
|
|
|
24
24
|
get method() {
|
|
25
25
|
return this.ctx.method;
|
|
26
26
|
}
|
|
27
|
+
get headers() {
|
|
28
|
+
return this.ctx.headers;
|
|
29
|
+
}
|
|
27
30
|
get locale() {
|
|
28
31
|
return this.ctx.locale;
|
|
29
32
|
}
|
|
@@ -54,7 +57,7 @@ export default class KoaRequest {
|
|
|
54
57
|
return !this.hasJsonParam() || this.ctx.request.accepts('json') === 'json';
|
|
55
58
|
}
|
|
56
59
|
getRuntimeContext(defaultRuntimeEnvironment) {
|
|
57
|
-
const { format, apiVersion, compat, locale, environment } = this.params;
|
|
60
|
+
const { format, apiVersion, compat, locale, environment, bundleSpecifier } = this.params;
|
|
58
61
|
const { debug } = this.ctx.request.query;
|
|
59
62
|
return {
|
|
60
63
|
runtimeEnvironment: {
|
|
@@ -63,6 +66,7 @@ export default class KoaRequest {
|
|
|
63
66
|
compat: compat !== undefined ? compat : defaultRuntimeEnvironment.compat,
|
|
64
67
|
debug: debug !== undefined ? true : defaultRuntimeEnvironment.debug,
|
|
65
68
|
apiVersion: apiVersion ? apiVersion : defaultRuntimeEnvironment.apiVersion,
|
|
69
|
+
bundle: bundleSpecifier !== undefined ? true : false, // the absence of a bundle strategy means bundling is off
|
|
66
70
|
},
|
|
67
71
|
runtimeParams: {
|
|
68
72
|
locale: locale
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.7.0-alpha.10",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"build/**/*.d.ts"
|
|
31
31
|
],
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@lwrjs/types": "0.
|
|
33
|
+
"@lwrjs/types": "0.7.0-alpha.10",
|
|
34
34
|
"@types/koa-compress": "^4.0.1",
|
|
35
35
|
"@types/koa__router": "^8.0.4",
|
|
36
36
|
"@types/spdy": "^3.4.4",
|
|
@@ -38,17 +38,22 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@koa/router": "^10.0.0",
|
|
41
|
-
"@lwrjs/shared-utils": "0.
|
|
41
|
+
"@lwrjs/shared-utils": "0.7.0-alpha.10",
|
|
42
|
+
"@types/compression": "^1.7.2",
|
|
42
43
|
"@types/express": "^4.17.11",
|
|
43
44
|
"@types/koa": "^2.11.7",
|
|
45
|
+
"compression": "^1.7.4",
|
|
44
46
|
"express": "^4.17.1",
|
|
45
47
|
"koa": "^2.13.1",
|
|
46
48
|
"koa-compose": "^4.1.0",
|
|
47
49
|
"koa-compress": "^5.0.1",
|
|
48
|
-
"shrink-ray-current": "^4.1.2",
|
|
49
50
|
"spdy": "^4.0.2"
|
|
50
51
|
},
|
|
52
|
+
"optionalDependencies": {
|
|
53
|
+
"shrink-ray-current": "^4.1.2"
|
|
54
|
+
},
|
|
51
55
|
"engines": {
|
|
52
56
|
"node": ">=14.15.4 <17"
|
|
53
|
-
}
|
|
57
|
+
},
|
|
58
|
+
"gitHead": "83c1e65e2169094cb55ac2c37e5aef16d3a9aa4a"
|
|
54
59
|
}
|