@sitecore-jss/sitecore-jss-proxy 13.2.5-canary.2 → 13.3.0-canary.1

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/index.js CHANGED
@@ -55,6 +55,7 @@ var set_cookie_parser_1 = __importDefault(require("set-cookie-parser"));
55
55
  var http_status_codes_1 = __importDefault(require("http-status-codes"));
56
56
  var zlib_1 = __importDefault(require("zlib")); // node.js standard lib
57
57
  var util_1 = require("./util");
58
+ // tslint:disable:max-line-length
58
59
  // For some reason, every other response returned by Sitecore contains the 'set-cookie' header with the SC_ANALYTICS_GLOBAL_COOKIE value as an empty string.
59
60
  // This effectively sets the cookie to empty on the client as well, so if a user were to close their browser
60
61
  // after one of these 'empty value' responses, they would not be tracked as a returning visitor after re-opening their browser.
@@ -82,8 +83,7 @@ function renderAppToResponse(proxyResponse, request, serverResponse, renderer, c
82
83
  return __awaiter(this, void 0, void 0, function () {
83
84
  var responseString;
84
85
  return __generator(this, function (_a) {
85
- if (proxyResponse.statusCode === http_status_codes_1.default.OK ||
86
- proxyResponse.statusCode === http_status_codes_1.default.NOT_FOUND) {
86
+ if (proxyResponse.statusCode === http_status_codes_1.default.OK || proxyResponse.statusCode === http_status_codes_1.default.NOT_FOUND) {
87
87
  responseString = void 0;
88
88
  if (contentEncoding &&
89
89
  (contentEncoding.indexOf('gzip') !== -1 || contentEncoding.indexOf('deflate') !== -1)) {
@@ -400,26 +400,13 @@ function isUrlIgnored(originalUrl, config, noDebug) {
400
400
  return false;
401
401
  }
402
402
  function handleProxyRequest(proxyReq, req, res, config, customOnProxyReq) {
403
- var _a;
404
403
  // if a HEAD request, we still need to issue a GET so we can return accurate headers
405
- if (!isUrlIgnored(req.originalUrl, config, true)) {
406
- // In case 'followRedirects' is enabled, and before the proxy was initialized we had set 'originalMethod'
407
- // now we need to set req.method back to original one, since proxyReq is already initialized.
408
- // See more info in 'preProxyHandler'
409
- if (((_a = config.proxyOptions) === null || _a === void 0 ? void 0 : _a.followRedirects) && req.originalMethod === 'HEAD') {
410
- req.method = req.originalMethod;
411
- delete req.originalMethod;
412
- if (config.debug) {
413
- console.log('DEBUG: Rewriting HEAD request to GET to create accurate headers');
414
- }
415
- }
416
- else if (proxyReq.method === 'HEAD') {
417
- if (config.debug) {
418
- console.log('DEBUG: Rewriting HEAD request to GET to create accurate headers');
419
- }
420
- // if a HEAD request, we still need to issue a GET so we can return accurate headers
421
- proxyReq.method = 'GET';
404
+ // proxyReq defined as 'any' to allow us to mutate this
405
+ if (proxyReq.method === 'HEAD' && !isUrlIgnored(req.originalUrl, config, true)) {
406
+ if (config.debug) {
407
+ console.log('DEBUG: Rewriting HEAD request to GET to create accurate headers');
422
408
  }
409
+ proxyReq.method = 'GET';
423
410
  }
424
411
  // invoke custom onProxyReq
425
412
  if (customOnProxyReq) {
@@ -441,26 +428,10 @@ function createOptions(renderer, config, parseRouteUrl) {
441
428
  console.log('DEBUG: Final proxy config', config);
442
429
  }
443
430
  var customOnProxyReq = (_a = config.proxyOptions) === null || _a === void 0 ? void 0 : _a.onProxyReq;
444
- return __assign(__assign({}, config.proxyOptions), { target: config.apiHost, changeOrigin: true, ws: true, pathRewrite: function (reqPath, req) { return rewriteRequestPath(reqPath, req, config, parseRouteUrl); }, logLevel: config.debug ? 'debug' : 'info', onProxyReq: function (proxyReq, req, res) {
445
- return handleProxyRequest(proxyReq, req, res, config, customOnProxyReq);
446
- }, onProxyRes: function (proxyRes, req, res) { return handleProxyResponse(proxyRes, req, res, renderer, config); } });
431
+ return __assign(__assign({}, config.proxyOptions), { target: config.apiHost, changeOrigin: true, ws: true, pathRewrite: function (reqPath, req) { return rewriteRequestPath(reqPath, req, config, parseRouteUrl); }, logLevel: config.debug ? 'debug' : 'info', onProxyReq: function (proxyReq, req, res) { return handleProxyRequest(proxyReq, req, res, config, customOnProxyReq); }, onProxyRes: function (proxyRes, req, res) { return handleProxyResponse(proxyRes, req, res, renderer, config); } });
447
432
  }
448
433
  function scProxy(renderer, config, parseRouteUrl) {
449
434
  var options = createOptions(renderer, config, parseRouteUrl);
450
- var preProxyHandler = function (req, _res, next) {
451
- // When 'followRedirects' is enabled, 'onProxyReq' is executed after 'proxyReq' is initialized based on original 'req'
452
- // and there are no public properties/methods to modify Redirectable 'proxyReq'.
453
- // so, we need to set 'HEAD' req as 'GET' before the proxy is initialized.
454
- // During the 'onProxyReq' event we will set 'req.method' back as 'HEAD'.
455
- // if a HEAD request, we need to issue a GET so we can return accurate headers
456
- if (req.method === 'HEAD' &&
457
- options.followRedirects &&
458
- !isUrlIgnored(req.originalUrl, config, true)) {
459
- req.method = 'GET';
460
- req.originalMethod = 'HEAD';
461
- }
462
- next();
463
- };
464
- return [preProxyHandler, http_proxy_middleware_1.default(options)];
435
+ return http_proxy_middleware_1.default(options);
465
436
  }
466
437
  exports.default = scProxy;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-jss/sitecore-jss-proxy",
3
- "version": "13.2.5-canary.2",
3
+ "version": "13.3.0-canary.1",
4
4
  "description": "Proxy middleware for express.js server.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -42,5 +42,5 @@
42
42
  "typescript": "^3.1.3"
43
43
  },
44
44
  "types": "types/index.d.ts",
45
- "gitHead": "e55d15ad7d6b3498d9d1c285a7d3640cc2f9a5f3"
45
+ "gitHead": "d14faceab632cd297689b615bd001a7c81cdf1a5"
46
46
  }
package/types/index.d.ts CHANGED
@@ -1,11 +1,7 @@
1
- /// <reference types="node" />
2
- import { IncomingMessage } from 'http';
1
+ /// <reference types="connect" />
3
2
  import { AppRenderer } from './AppRenderer';
4
3
  import { ProxyConfig } from './ProxyConfig';
5
4
  import { RouteUrlParser } from './RouteUrlParser';
6
- export interface ProxyIncomingMessage extends IncomingMessage {
7
- originalUrl: string;
8
- }
9
5
  export declare const removeEmptyAnalyticsCookie: (proxyResponse: any) => void;
10
6
  export declare function rewriteRequestPath(reqPath: string, req: any, config: ProxyConfig, parseRouteUrl?: RouteUrlParser): string;
11
- export default function scProxy(renderer: AppRenderer, config: ProxyConfig, parseRouteUrl: RouteUrlParser): any[];
7
+ export default function scProxy(renderer: AppRenderer, config: ProxyConfig, parseRouteUrl: RouteUrlParser): import("connect").NextHandleFunction;