@lwrjs/server 0.15.0-alpha.9 → 0.15.0

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.
@@ -100,7 +100,7 @@ var AbstractMiddlewareRequest = class {
100
100
  if (host && !host.startsWith("http")) {
101
101
  host = `${this.headers?.["x-forwarded-proto"] || this.protocol}://${host}`;
102
102
  }
103
- const requestDepth = (0, import_shared_utils.parseRequestDepthHeader)(this.headers) + 1;
103
+ const requestDepth = (0, import_shared_utils.parseRequestDepth)(this.headers, this.query) + 1;
104
104
  const basePath = runtimeEnvironment.basePath;
105
105
  const defaultLocale = runtimeEnvironment.i18n.defaultLocale;
106
106
  const locale = localeParam || this.locale || defaultLocale;
@@ -120,4 +120,13 @@ var AbstractMiddlewareRequest = class {
120
120
  runtimeParams
121
121
  };
122
122
  }
123
+ getCoreProxy(appCoreProxy, proxyForSSR = false) {
124
+ const origin = process.env.CORE_ORIGIN;
125
+ const host = process.env.CORE_HOST;
126
+ const servername = process.env.CORE_SERVERNAME;
127
+ const override = process.env.PROXY_FOR_SSR;
128
+ if (override === "false" || !proxyForSSR && override !== "true")
129
+ return void 0;
130
+ return origin ? {origin, host, servername} : appCoreProxy;
131
+ }
123
132
  };
@@ -35,6 +35,9 @@ var ExpressInternalServer = class extends import_abstract_internal_app_server.de
35
35
  constructor(options) {
36
36
  super();
37
37
  this.expressApp = options?.app || (0, import_express.default)();
38
+ if (!options?.app) {
39
+ this.expressApp.set("case sensitive routing", options?.caseSensitiveRoutes);
40
+ }
38
41
  if (options.basePath) {
39
42
  this.basePath = options.basePath;
40
43
  }
@@ -60,7 +60,10 @@ var FsInternalServer = class extends import_abstract_internal_app_server.default
60
60
  super();
61
61
  this.middlewares = [];
62
62
  this.lwrFsKoaApp = new LwrFsKoa();
63
- this.koaRouter = options.basePath ? new import_router.default({prefix: options.basePath}) : new import_router.default();
63
+ this.koaRouter = new import_router.default({
64
+ prefix: options.basePath ?? void 0,
65
+ sensitive: options.caseSensitiveRoutes
66
+ });
64
67
  }
65
68
  createHttpServer() {
66
69
  return import_http.default.createServer();
@@ -36,7 +36,10 @@ var KoaInternalServer = class extends import_abstract_internal_app_server.defaul
36
36
  constructor(options) {
37
37
  super();
38
38
  this.koaApp = new import_koa.default();
39
- this.koaRouter = options.basePath ? new import_router.default({prefix: options.basePath}) : new import_router.default();
39
+ this.koaRouter = new import_router.default({
40
+ prefix: options.basePath ?? void 0,
41
+ sensitive: options.caseSensitiveRoutes
42
+ });
40
43
  }
41
44
  getImpl() {
42
45
  return this.koaApp;
@@ -1,4 +1,4 @@
1
- import type { RuntimeContext, RuntimeEnvironment, Headers, MiddlewareRequest, NormalizedLwrGlobalConfig } from '@lwrjs/types';
1
+ import type { RuntimeContext, RuntimeEnvironment, Headers, MiddlewareRequest, NormalizedLwrGlobalConfig, DirectToCoreProxy } from '@lwrjs/types';
2
2
  export declare abstract class AbstractMiddlewareRequest implements MiddlewareRequest {
3
3
  isSiteGenerationRequest: boolean;
4
4
  constructor(isSiteGenerationRequest?: boolean);
@@ -22,5 +22,6 @@ export declare abstract class AbstractMiddlewareRequest implements MiddlewareReq
22
22
  validateEnvironmentRequest(config: NormalizedLwrGlobalConfig): boolean;
23
23
  validateApiVersion(config: NormalizedLwrGlobalConfig): boolean;
24
24
  getRuntimeContext(defaultRuntimeEnvironment: RuntimeEnvironment): RuntimeContext;
25
+ getCoreProxy(appCoreProxy?: DirectToCoreProxy, proxyForSSR?: boolean): DirectToCoreProxy | undefined;
25
26
  }
26
27
  //# sourceMappingURL=abstract-request.d.ts.map
@@ -1,4 +1,4 @@
1
- import { parseRequestDepthHeader } from '@lwrjs/shared-utils';
1
+ import { parseRequestDepth } from '@lwrjs/shared-utils';
2
2
  // See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded
3
3
  function parseForwardedHeader(forwarded) {
4
4
  if (!forwarded)
@@ -76,7 +76,7 @@ export class AbstractMiddlewareRequest {
76
76
  host = `${this.headers?.['x-forwarded-proto'] || this.protocol}://${host}`;
77
77
  }
78
78
  // Increment the depth for any fetch calls
79
- const requestDepth = parseRequestDepthHeader(this.headers) + 1;
79
+ const requestDepth = parseRequestDepth(this.headers, this.query) + 1;
80
80
  const basePath = runtimeEnvironment.basePath;
81
81
  const defaultLocale = runtimeEnvironment.i18n.defaultLocale;
82
82
  const locale = localeParam || this.locale || defaultLocale;
@@ -101,5 +101,19 @@ export class AbstractMiddlewareRequest {
101
101
  runtimeParams,
102
102
  };
103
103
  }
104
+ getCoreProxy(appCoreProxy, proxyForSSR = false) {
105
+ const origin = process.env.CORE_ORIGIN;
106
+ const host = process.env.CORE_HOST;
107
+ const servername = process.env.CORE_SERVERNAME;
108
+ const override = process.env.PROXY_FOR_SSR;
109
+ // override the value of the route-level bootstrap proxyForSSR flag:
110
+ // "false" => override the route-level flag to be false
111
+ // "true" => override the route-level flag to be true
112
+ // empty/unset -> use route-level flag as-is
113
+ if (override === 'false' || (!proxyForSSR && override !== 'true'))
114
+ return undefined;
115
+ // origin is required to proxy to Core
116
+ return origin ? { origin, host, servername } : appCoreProxy;
117
+ }
104
118
  }
105
119
  //# sourceMappingURL=abstract-request.js.map
@@ -10,6 +10,9 @@ export default class ExpressInternalServer extends AbstractInternalAppServer {
10
10
  constructor(options) {
11
11
  super();
12
12
  this.expressApp = options?.app || express();
13
+ if (!options?.app) {
14
+ this.expressApp.set('case sensitive routing', options?.caseSensitiveRoutes);
15
+ }
13
16
  if (options.basePath) {
14
17
  this.basePath = options.basePath;
15
18
  }
@@ -34,7 +34,10 @@ export class FsInternalServer extends AbstractInternalAppServer {
34
34
  super();
35
35
  this.middlewares = [];
36
36
  this.lwrFsKoaApp = new LwrFsKoa();
37
- this.koaRouter = options.basePath ? new KoaRouter({ prefix: options.basePath }) : new KoaRouter();
37
+ this.koaRouter = new KoaRouter({
38
+ prefix: options.basePath ?? undefined,
39
+ sensitive: options.caseSensitiveRoutes,
40
+ });
38
41
  }
39
42
  // TODO: mock this API as is not used for now
40
43
  createHttpServer() {
@@ -1,11 +1,7 @@
1
1
  import { LwrFsKoa } from './fs/fs-server.js';
2
- import type { InternalAppServer, MiddlewareRequest, MiddlewareResponse, ServerTypeImpl, ServerTypes } from '@lwrjs/types';
2
+ import type { InternalAppServer, InternalAppServerOptions, MiddlewareRequest, MiddlewareResponse, ServerTypes } from '@lwrjs/types';
3
3
  import type { Request, Response } from 'express';
4
- type ServerOptions = {
5
- app?: ServerTypeImpl<ServerTypes>;
6
- basePath?: string;
7
- };
8
- declare function createInternalServer<T extends ServerTypes>(serverType?: string, options?: ServerOptions): InternalAppServer<T>;
4
+ declare function createInternalServer<T extends ServerTypes>(serverType?: string, options?: InternalAppServerOptions): InternalAppServer<T>;
9
5
  declare function mockMiddlewareRequest(req: Request): MiddlewareRequest;
10
6
  declare function mockMiddlewareResponse(res: Response): MiddlewareResponse;
11
7
  export { createInternalServer, mockMiddlewareRequest, mockMiddlewareResponse, LwrFsKoa };
@@ -11,7 +11,10 @@ export default class KoaInternalServer extends AbstractInternalAppServer {
11
11
  constructor(options) {
12
12
  super();
13
13
  this.koaApp = new Koa();
14
- this.koaRouter = options.basePath ? new KoaRouter({ prefix: options.basePath }) : new KoaRouter();
14
+ this.koaRouter = new KoaRouter({
15
+ prefix: options.basePath ?? undefined,
16
+ sensitive: options.caseSensitiveRoutes,
17
+ });
15
18
  }
16
19
  getImpl() {
17
20
  return this.koaApp;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.15.0-alpha.9",
7
+ "version": "0.15.0",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -37,24 +37,24 @@
37
37
  "build": "tsc -b"
38
38
  },
39
39
  "devDependencies": {
40
- "@lwrjs/types": "0.15.0-alpha.9",
40
+ "@lwrjs/types": "0.15.0",
41
41
  "@types/koa-compress": "^4.0.6",
42
42
  "@types/koa__router": "^8.0.4",
43
43
  "jest-express": "^1.12.0"
44
44
  },
45
45
  "dependencies": {
46
46
  "@koa/router": "^10.0.0",
47
- "@lwrjs/diagnostics": "0.15.0-alpha.9",
48
- "@lwrjs/instrumentation": "0.15.0-alpha.9",
49
- "@lwrjs/shared-utils": "0.15.0-alpha.9",
47
+ "@lwrjs/diagnostics": "0.15.0",
48
+ "@lwrjs/instrumentation": "0.15.0",
49
+ "@lwrjs/shared-utils": "0.15.0",
50
50
  "@types/express": "^4.17.21",
51
51
  "@types/koa": "^2.15.0",
52
- "express": "^4.19.2",
52
+ "express": "^4.20.0",
53
53
  "koa": "^2.15.3",
54
54
  "koa-compose": "^4.1.0"
55
55
  },
56
56
  "engines": {
57
57
  "node": ">=18.0.0"
58
58
  },
59
- "gitHead": "9783b817b11c29ca385457683fcb87e8179f7902"
59
+ "gitHead": "ee374df435d5342f63e4da126a09461e761837f3"
60
60
  }