@lwrjs/server 0.6.0-alpha.9 → 0.6.2
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/cjs/express/express-request.cjs +17 -0
- package/build/cjs/express/express-response.cjs +4 -0
- package/build/cjs/express/express-server.cjs +11 -2
- package/build/cjs/fs/fs-response.cjs +3 -0
- package/build/cjs/index.cjs +2 -2
- package/build/cjs/koa/koa-request.cjs +15 -0
- package/build/cjs/koa/koa-response.cjs +4 -0
- package/build/es/express/express-request.d.ts +5 -0
- package/build/es/express/express-request.js +19 -0
- package/build/es/express/express-response.d.ts +1 -0
- package/build/es/express/express-response.js +5 -0
- package/build/es/express/express-server.d.ts +3 -2
- package/build/es/express/express-server.js +12 -2
- package/build/es/fs/fs-response.d.ts +1 -0
- package/build/es/fs/fs-response.js +4 -0
- package/build/es/index.d.ts +4 -1
- package/build/es/index.js +2 -2
- package/build/es/koa/koa-request.d.ts +5 -0
- package/build/es/koa/koa-request.js +15 -0
- package/build/es/koa/koa-response.d.ts +1 -0
- package/build/es/koa/koa-response.js +5 -0
- package/package.json +4 -4
|
@@ -27,6 +27,15 @@ var ExpressRequest = class {
|
|
|
27
27
|
get query() {
|
|
28
28
|
return this.req.query;
|
|
29
29
|
}
|
|
30
|
+
get body() {
|
|
31
|
+
return this.req.body;
|
|
32
|
+
}
|
|
33
|
+
get method() {
|
|
34
|
+
return this.req.method;
|
|
35
|
+
}
|
|
36
|
+
get protocol() {
|
|
37
|
+
return this.req.protocol;
|
|
38
|
+
}
|
|
30
39
|
get locale() {
|
|
31
40
|
return this.req.locale;
|
|
32
41
|
}
|
|
@@ -36,6 +45,14 @@ var ExpressRequest = class {
|
|
|
36
45
|
acceptsLanguages() {
|
|
37
46
|
return this.req.acceptsLanguages();
|
|
38
47
|
}
|
|
48
|
+
get(field) {
|
|
49
|
+
return this.req.get(field);
|
|
50
|
+
}
|
|
51
|
+
cookie(key) {
|
|
52
|
+
const rawCookies = (this.req.headers.cookie?.split(";") || []).map((c) => c.trim());
|
|
53
|
+
const rawCookie = rawCookies.find((c) => c.startsWith(`${key}=`));
|
|
54
|
+
return rawCookie ? decodeURIComponent(rawCookie.replace(`${key}=`, "")) : void 0;
|
|
55
|
+
}
|
|
39
56
|
hasJsonParam() {
|
|
40
57
|
return this.req.query.json !== void 0;
|
|
41
58
|
}
|
|
@@ -34,15 +34,24 @@ var import_abstract_internal_app_server = __toModule(require("../common/abstract
|
|
|
34
34
|
var import_express_request = __toModule(require("./express-request.cjs"));
|
|
35
35
|
var import_express_response = __toModule(require("./express-response.cjs"));
|
|
36
36
|
var ExpressInternalServer = class extends import_abstract_internal_app_server.default {
|
|
37
|
-
constructor() {
|
|
37
|
+
constructor(options) {
|
|
38
38
|
super();
|
|
39
39
|
this.expressApp = (0, import_express.default)();
|
|
40
|
+
if (options.basePath) {
|
|
41
|
+
this.basePath = options.basePath;
|
|
42
|
+
}
|
|
40
43
|
}
|
|
41
44
|
getImpl() {
|
|
42
45
|
return this.expressApp;
|
|
43
46
|
}
|
|
44
47
|
createHttpServer() {
|
|
45
|
-
|
|
48
|
+
if (this.basePath) {
|
|
49
|
+
const server = (0, import_express.default)();
|
|
50
|
+
server.use(this.basePath, this.expressApp);
|
|
51
|
+
this.httpServer = import_http.default.createServer(server);
|
|
52
|
+
} else {
|
|
53
|
+
this.httpServer = import_http.default.createServer(this.expressApp);
|
|
54
|
+
}
|
|
46
55
|
return this.httpServer;
|
|
47
56
|
}
|
|
48
57
|
createHttp2Server() {
|
package/build/cjs/index.cjs
CHANGED
|
@@ -35,9 +35,9 @@ var import_express_response = __toModule(require("./express/express-response.cjs
|
|
|
35
35
|
var import_koa_server = __toModule(require("./koa/koa-server.cjs"));
|
|
36
36
|
var import_fs_server = __toModule(require("./fs/fs-server.cjs"));
|
|
37
37
|
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
38
|
-
function createInternalServer(serverType = "express") {
|
|
38
|
+
function createInternalServer(serverType = "express", options = {}) {
|
|
39
39
|
if (serverType === "express") {
|
|
40
|
-
const expressAppServer = new import_express_server.default();
|
|
40
|
+
const expressAppServer = new import_express_server.default(options);
|
|
41
41
|
return expressAppServer;
|
|
42
42
|
}
|
|
43
43
|
if (serverType === "koa") {
|
|
@@ -27,6 +27,15 @@ var KoaRequest = class {
|
|
|
27
27
|
get query() {
|
|
28
28
|
return this.ctx.request.query;
|
|
29
29
|
}
|
|
30
|
+
get protocol() {
|
|
31
|
+
return this.ctx.protocol;
|
|
32
|
+
}
|
|
33
|
+
get body() {
|
|
34
|
+
return this.ctx.body;
|
|
35
|
+
}
|
|
36
|
+
get method() {
|
|
37
|
+
return this.ctx.method;
|
|
38
|
+
}
|
|
30
39
|
get locale() {
|
|
31
40
|
return this.ctx.locale;
|
|
32
41
|
}
|
|
@@ -39,6 +48,12 @@ var KoaRequest = class {
|
|
|
39
48
|
acceptsLanguages() {
|
|
40
49
|
return this.ctx.request.acceptsLanguages();
|
|
41
50
|
}
|
|
51
|
+
get(field) {
|
|
52
|
+
return this.ctx.get(field);
|
|
53
|
+
}
|
|
54
|
+
cookie(key) {
|
|
55
|
+
return this.ctx.cookies.get(key);
|
|
56
|
+
}
|
|
42
57
|
hasJsonParam() {
|
|
43
58
|
return this.ctx.query.json !== void 0;
|
|
44
59
|
}
|
|
@@ -8,9 +8,14 @@ export default class ExpressRequest implements MiddlewareRequest {
|
|
|
8
8
|
get originalUrl(): string;
|
|
9
9
|
get path(): string;
|
|
10
10
|
get query(): any;
|
|
11
|
+
get body(): any;
|
|
12
|
+
get method(): string;
|
|
13
|
+
get protocol(): any;
|
|
11
14
|
get locale(): string;
|
|
12
15
|
set locale(l: string);
|
|
13
16
|
acceptsLanguages(): string[];
|
|
17
|
+
get(field: string): string | undefined;
|
|
18
|
+
cookie(key: string): string | undefined;
|
|
14
19
|
hasJsonParam(): boolean;
|
|
15
20
|
isJsonRequest(): boolean;
|
|
16
21
|
isSiteGeneration(): boolean;
|
|
@@ -15,6 +15,16 @@ export default class ExpressRequest {
|
|
|
15
15
|
get query() {
|
|
16
16
|
return this.req.query;
|
|
17
17
|
}
|
|
18
|
+
get body() {
|
|
19
|
+
// requires body parsing middleware
|
|
20
|
+
return this.req.body;
|
|
21
|
+
}
|
|
22
|
+
get method() {
|
|
23
|
+
return this.req.method;
|
|
24
|
+
}
|
|
25
|
+
get protocol() {
|
|
26
|
+
return this.req.protocol;
|
|
27
|
+
}
|
|
18
28
|
get locale() {
|
|
19
29
|
return this.req.locale;
|
|
20
30
|
}
|
|
@@ -24,6 +34,15 @@ export default class ExpressRequest {
|
|
|
24
34
|
acceptsLanguages() {
|
|
25
35
|
return this.req.acceptsLanguages();
|
|
26
36
|
}
|
|
37
|
+
get(field) {
|
|
38
|
+
return this.req.get(field);
|
|
39
|
+
}
|
|
40
|
+
cookie(key) {
|
|
41
|
+
// Does not require the cookie-parser middleware
|
|
42
|
+
const rawCookies = (this.req.headers.cookie?.split(';') || []).map((c) => c.trim());
|
|
43
|
+
const rawCookie = rawCookies.find((c) => c.startsWith(`${key}=`));
|
|
44
|
+
return rawCookie ? decodeURIComponent(rawCookie.replace(`${key}=`, '')) : undefined;
|
|
45
|
+
}
|
|
27
46
|
hasJsonParam() {
|
|
28
47
|
return this.req.query.json !== undefined;
|
|
29
48
|
}
|
|
@@ -15,5 +15,6 @@ export default class ExpressResponse implements MiddlewareResponse {
|
|
|
15
15
|
sendStatus(httpCode: number): void;
|
|
16
16
|
stream(stream: Readable): void;
|
|
17
17
|
type(type: string): MiddlewareResponse;
|
|
18
|
+
cookie(name: string, value: string, options: any): MiddlewareResponse;
|
|
18
19
|
}
|
|
19
20
|
//# sourceMappingURL=express-response.d.ts.map
|
|
@@ -54,5 +54,10 @@ export default class ExpressResponse {
|
|
|
54
54
|
this.res.type(type);
|
|
55
55
|
return this;
|
|
56
56
|
}
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
58
|
+
cookie(name, value, options) {
|
|
59
|
+
this.res.cookie(name, value, options);
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
57
62
|
}
|
|
58
63
|
//# sourceMappingURL=express-response.js.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Application as ExpressApp } from 'express';
|
|
3
3
|
import http from 'http';
|
|
4
4
|
import http2 from 'http2';
|
|
5
|
-
import { InternalAppServer } from '@lwrjs/types';
|
|
5
|
+
import { InternalAppServer, InternalAppServerOptions } from '@lwrjs/types';
|
|
6
6
|
import AbstractInternalAppServer from '../common/abstract-internal-app-server.js';
|
|
7
7
|
/**
|
|
8
8
|
* Express Server Implementation (https://expressjs.com/)
|
|
@@ -11,7 +11,8 @@ export default class ExpressInternalServer extends AbstractInternalAppServer imp
|
|
|
11
11
|
private expressApp;
|
|
12
12
|
private httpServer?;
|
|
13
13
|
private http2Server?;
|
|
14
|
-
|
|
14
|
+
private basePath?;
|
|
15
|
+
constructor(options: InternalAppServerOptions);
|
|
15
16
|
getImpl(): ExpressApp;
|
|
16
17
|
createHttpServer(): http.Server;
|
|
17
18
|
createHttp2Server(): http2.Http2Server;
|
|
@@ -9,15 +9,25 @@ import ExpressResponse from './express-response.js';
|
|
|
9
9
|
* Express Server Implementation (https://expressjs.com/)
|
|
10
10
|
*/
|
|
11
11
|
export default class ExpressInternalServer extends AbstractInternalAppServer {
|
|
12
|
-
constructor() {
|
|
12
|
+
constructor(options) {
|
|
13
13
|
super();
|
|
14
14
|
this.expressApp = express();
|
|
15
|
+
if (options.basePath) {
|
|
16
|
+
this.basePath = options.basePath;
|
|
17
|
+
}
|
|
15
18
|
}
|
|
16
19
|
getImpl() {
|
|
17
20
|
return this.expressApp;
|
|
18
21
|
}
|
|
19
22
|
createHttpServer() {
|
|
20
|
-
|
|
23
|
+
if (this.basePath) {
|
|
24
|
+
const server = express();
|
|
25
|
+
server.use(this.basePath, this.expressApp);
|
|
26
|
+
this.httpServer = http.createServer(server);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
this.httpServer = http.createServer(this.expressApp);
|
|
30
|
+
}
|
|
21
31
|
return this.httpServer;
|
|
22
32
|
}
|
|
23
33
|
createHttp2Server() {
|
|
@@ -13,5 +13,6 @@ export default class FsResponse implements MiddlewareResponse {
|
|
|
13
13
|
sendStatus(httpCode: number): void;
|
|
14
14
|
stream(stream: Readable): void;
|
|
15
15
|
type(type: string): MiddlewareResponse;
|
|
16
|
+
cookie(name: string, value: string, options: any): MiddlewareResponse;
|
|
16
17
|
}
|
|
17
18
|
//# sourceMappingURL=fs-response.d.ts.map
|
|
@@ -33,5 +33,9 @@ export default class FsResponse {
|
|
|
33
33
|
this.context.fs.type = type;
|
|
34
34
|
return this;
|
|
35
35
|
}
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
37
|
+
cookie(name, value, options) {
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
36
40
|
}
|
|
37
41
|
//# sourceMappingURL=fs-response.js.map
|
package/build/es/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { LwrFsKoa } from './fs/fs-server.js';
|
|
2
2
|
import { InternalAppServer, MiddlewareRequest, MiddlewareResponse, ServerTypes } from '@lwrjs/types';
|
|
3
3
|
import { Request, Response } from 'express';
|
|
4
|
-
declare
|
|
4
|
+
declare type ServerOptions = {
|
|
5
|
+
basePath?: string;
|
|
6
|
+
};
|
|
7
|
+
declare function createInternalServer<T extends ServerTypes>(serverType?: string, options?: ServerOptions): InternalAppServer<T>;
|
|
5
8
|
declare function mockMiddlewareRequest(req: Request): MiddlewareRequest;
|
|
6
9
|
declare function mockMiddlewareResponse(res: Response): MiddlewareResponse;
|
|
7
10
|
export { createInternalServer, mockMiddlewareRequest, mockMiddlewareResponse, LwrFsKoa };
|
package/build/es/index.js
CHANGED
|
@@ -4,9 +4,9 @@ import ExpressResponse from './express/express-response.js';
|
|
|
4
4
|
import KoaInternalServer from './koa/koa-server.js';
|
|
5
5
|
import { FsInternalServer, LwrFsKoa } from './fs/fs-server.js';
|
|
6
6
|
import { createSingleDiagnosticError, descriptions, LwrConfigValidationError } from '@lwrjs/diagnostics';
|
|
7
|
-
function createInternalServer(serverType = 'express') {
|
|
7
|
+
function createInternalServer(serverType = 'express', options = {}) {
|
|
8
8
|
if (serverType === 'express') {
|
|
9
|
-
const expressAppServer = new ExpressInternalServer();
|
|
9
|
+
const expressAppServer = new ExpressInternalServer(options);
|
|
10
10
|
return expressAppServer;
|
|
11
11
|
}
|
|
12
12
|
if (serverType === 'koa') {
|
|
@@ -8,10 +8,15 @@ export default class KoaRequest implements MiddlewareRequest {
|
|
|
8
8
|
get originalUrl(): string;
|
|
9
9
|
get path(): string;
|
|
10
10
|
get query(): any;
|
|
11
|
+
get protocol(): any;
|
|
12
|
+
get body(): any;
|
|
13
|
+
get method(): string;
|
|
11
14
|
get locale(): string;
|
|
12
15
|
set locale(l: string);
|
|
13
16
|
isSiteGeneration(): boolean;
|
|
14
17
|
acceptsLanguages(): string[];
|
|
18
|
+
get(field: string): string | undefined;
|
|
19
|
+
cookie(key: string): string | undefined;
|
|
15
20
|
hasJsonParam(): boolean;
|
|
16
21
|
isJsonRequest(): boolean;
|
|
17
22
|
validateJsonRequest(): boolean;
|
|
@@ -15,6 +15,15 @@ export default class KoaRequest {
|
|
|
15
15
|
get query() {
|
|
16
16
|
return this.ctx.request.query;
|
|
17
17
|
}
|
|
18
|
+
get protocol() {
|
|
19
|
+
return this.ctx.protocol;
|
|
20
|
+
}
|
|
21
|
+
get body() {
|
|
22
|
+
return this.ctx.body;
|
|
23
|
+
}
|
|
24
|
+
get method() {
|
|
25
|
+
return this.ctx.method;
|
|
26
|
+
}
|
|
18
27
|
get locale() {
|
|
19
28
|
return this.ctx.locale;
|
|
20
29
|
}
|
|
@@ -27,6 +36,12 @@ export default class KoaRequest {
|
|
|
27
36
|
acceptsLanguages() {
|
|
28
37
|
return this.ctx.request.acceptsLanguages();
|
|
29
38
|
}
|
|
39
|
+
get(field) {
|
|
40
|
+
return this.ctx.get(field);
|
|
41
|
+
}
|
|
42
|
+
cookie(key) {
|
|
43
|
+
return this.ctx.cookies.get(key);
|
|
44
|
+
}
|
|
30
45
|
hasJsonParam() {
|
|
31
46
|
return this.ctx.query.json !== undefined;
|
|
32
47
|
}
|
|
@@ -15,5 +15,6 @@ export default class KoaResponse implements MiddlewareResponse {
|
|
|
15
15
|
sendStatus(httpCode: number): void;
|
|
16
16
|
stream(stream: Readable): void;
|
|
17
17
|
type(type: string): MiddlewareResponse;
|
|
18
|
+
cookie(name: string, value: string, options: any): MiddlewareResponse;
|
|
18
19
|
}
|
|
19
20
|
//# sourceMappingURL=koa-response.d.ts.map
|
|
@@ -55,5 +55,10 @@ export default class KoaResponse {
|
|
|
55
55
|
this.ctx.type = type;
|
|
56
56
|
return this;
|
|
57
57
|
}
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
59
|
+
cookie(name, value, options) {
|
|
60
|
+
this.ctx.cookies.set(name, value, options);
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
58
63
|
}
|
|
59
64
|
//# sourceMappingURL=koa-response.js.map
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.6.
|
|
7
|
+
"version": "0.6.2",
|
|
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.6.
|
|
33
|
+
"@lwrjs/types": "0.6.2",
|
|
34
34
|
"@types/koa-compress": "^4.0.1",
|
|
35
35
|
"@types/koa__router": "^8.0.4",
|
|
36
36
|
"@types/spdy": "^3.4.4",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@koa/router": "^10.0.0",
|
|
41
|
-
"@lwrjs/shared-utils": "0.6.
|
|
41
|
+
"@lwrjs/shared-utils": "0.6.2",
|
|
42
42
|
"@types/express": "^4.17.11",
|
|
43
43
|
"@types/koa": "^2.11.7",
|
|
44
44
|
"express": "^4.17.1",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"engines": {
|
|
52
52
|
"node": ">=14.15.4 <17"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "ef85bdc48adde58b7c648561d67acbb408bbe189"
|
|
55
55
|
}
|