@sitecore-jss/sitecore-jss-proxy
Advanced tools
Comparing version 16.0.0-canary.8 to 16.0.0-canary.11
@@ -59,3 +59,2 @@ "use strict"; | ||
var util_1 = require("./util"); | ||
// tslint:disable:max-line-length | ||
// 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. | ||
@@ -82,4 +81,14 @@ // This effectively sets the cookie to empty on the client as well, so if a user were to close their browser | ||
// inspired by: http://stackoverflow.com/a/22487927/9324 | ||
/** | ||
* @param {IncomingMessage} proxyResponse | ||
* @param {IncomingMessage} request | ||
* @param {ServerResponse} serverResponse | ||
* @param {AppRenderer} renderer | ||
* @param {ProxyConfig} config | ||
*/ | ||
function renderAppToResponse(proxyResponse, request, serverResponse, renderer, config) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
/** | ||
* Extract layout service data from proxy response | ||
*/ | ||
function extractLayoutServiceDataFromProxyResponse() { | ||
@@ -117,3 +126,6 @@ return __awaiter(this, void 0, void 0, function () { | ||
} | ||
// function replies with HTTP 500 when an error occurs | ||
/** | ||
* function replies with HTTP 500 when an error occurs | ||
* @param {Error} error | ||
*/ | ||
function replyWithError(error) { | ||
@@ -144,2 +156,6 @@ return __awaiter(this, void 0, void 0, function () { | ||
// callback handles the result of server-side rendering | ||
/** | ||
* @param {Error | null} error | ||
* @param {RenderResponse} result | ||
*/ | ||
function handleRenderingResult(error, result) { | ||
@@ -185,3 +201,3 @@ return __awaiter(this, void 0, void 0, function () { | ||
} | ||
proxyResponse.headers['location'] = result.redirect; | ||
proxyResponse.headers.location = result.redirect; | ||
} | ||
@@ -199,2 +215,7 @@ finalStatusCode = result.status || proxyResponse.statusCode || http_status_codes_1.default.OK; | ||
} | ||
/** | ||
* @param {Buffer | null} content | ||
* @param {number} statusCode | ||
* @param {any} [headers] | ||
*/ | ||
function completeProxyResponse(content, statusCode, headers) { | ||
@@ -209,2 +230,5 @@ if (!headers) { | ||
} | ||
/** | ||
* @param {any} layoutServiceData | ||
*/ | ||
function createViewBag(layoutServiceData) { | ||
@@ -242,3 +266,3 @@ return __awaiter(this, void 0, void 0, function () { | ||
// remove IIS server header for security | ||
delete proxyResponse.headers['server']; | ||
delete proxyResponse.headers.server; | ||
if (config.setHeaders) { | ||
@@ -298,2 +322,9 @@ config.setHeaders(request, serverResponse, proxyResponse); | ||
} | ||
/** | ||
* @param {IncomingMessage} proxyResponse | ||
* @param {any} request | ||
* @param {ServerResponse} serverResponse | ||
* @param {AppRenderer} renderer | ||
* @param {ProxyConfig} config | ||
*/ | ||
function handleProxyResponse(proxyResponse, request, serverResponse, renderer, config) { | ||
@@ -318,2 +349,8 @@ exports.removeEmptyAnalyticsCookie(proxyResponse); | ||
} | ||
/** | ||
* @param {string} reqPath | ||
* @param {any} req | ||
* @param {ProxyConfig} config | ||
* @param {RouteUrlParser} parseRouteUrl | ||
*/ | ||
function rewriteRequestPath(reqPath, req, config, parseRouteUrl) { | ||
@@ -369,3 +406,3 @@ // the path comes in URL-encoded by default, | ||
if (config.debug) { | ||
console.log("DEBUG: parseRouteUrl() result", routeParams); | ||
console.log('DEBUG: parseRouteUrl() result', routeParams); | ||
} | ||
@@ -384,2 +421,7 @@ } | ||
exports.rewriteRequestPath = rewriteRequestPath; | ||
/** | ||
* @param {string} originalUrl | ||
* @param {ProxyConfig} config | ||
* @param {boolean} noDebug | ||
*/ | ||
function isUrlIgnored(originalUrl, config, noDebug) { | ||
@@ -419,2 +461,9 @@ if (noDebug === void 0) { noDebug = false; } | ||
} | ||
/** | ||
* @param {any} proxyReq | ||
* @param {any} req | ||
* @param {ServerResponse} res | ||
* @param {ProxyConfig} config | ||
* @param {Function} customOnProxyReq | ||
*/ | ||
function handleProxyRequest(proxyReq, req, res, config, customOnProxyReq) { | ||
@@ -434,2 +483,7 @@ // if a HEAD request, we still need to issue a GET so we can return accurate headers | ||
} | ||
/** | ||
* @param {AppRenderer} renderer | ||
* @param {ProxyConfig} config | ||
* @param {RouteUrlParser} parseRouteUrl | ||
*/ | ||
function createOptions(renderer, config, parseRouteUrl) { | ||
@@ -450,4 +504,11 @@ var _a; | ||
var customOnProxyReq = (_a = config.proxyOptions) === null || _a === void 0 ? void 0 : _a.onProxyReq; | ||
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); } }); | ||
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); } }); | ||
} | ||
/** | ||
* @param {AppRenderer} renderer | ||
* @param {ProxyConfig} config | ||
* @param {RouteUrlParser} parseRouteUrl | ||
*/ | ||
function scProxy(renderer, config, parseRouteUrl) { | ||
@@ -454,0 +515,0 @@ var options = createOptions(renderer, config, parseRouteUrl); |
{ | ||
"name": "@sitecore-jss/sitecore-jss-proxy", | ||
"version": "16.0.0-canary.8", | ||
"version": "16.0.0-canary.11", | ||
"description": "Proxy middleware for express.js server.", | ||
@@ -9,3 +9,3 @@ "main": "dist/index.js", | ||
"clean": "del-cli dist types", | ||
"lint": "tslint -p . -c ../../tslint.json \"src/**/*.ts\"", | ||
"lint": "eslint --fix ./src/**/*.ts", | ||
"test": "mocha --require ts-node/register \"./src/**/*.test.ts\"", | ||
@@ -40,2 +40,3 @@ "prepublishOnly": "npm run build", | ||
"del-cli": "^3.0.1", | ||
"eslint": "^7.15.0", | ||
"mocha": "^8.1.3", | ||
@@ -47,3 +48,3 @@ "sinon": "^7.0.0", | ||
"types": "types/index.d.ts", | ||
"gitHead": "be22a453049c318e28e73343974f371cc0300c7d" | ||
"gitHead": "efc18cfe8c16303e8f585bbbc3135b92d5fef162" | ||
} |
@@ -6,3 +6,14 @@ /// <reference types="connect" /> | ||
export declare const removeEmptyAnalyticsCookie: (proxyResponse: any) => void; | ||
/** | ||
* @param {string} reqPath | ||
* @param {any} req | ||
* @param {ProxyConfig} config | ||
* @param {RouteUrlParser} parseRouteUrl | ||
*/ | ||
export declare function rewriteRequestPath(reqPath: string, req: any, config: ProxyConfig, parseRouteUrl?: RouteUrlParser): string; | ||
/** | ||
* @param {AppRenderer} renderer | ||
* @param {ProxyConfig} config | ||
* @param {RouteUrlParser} parseRouteUrl | ||
*/ | ||
export default function scProxy(renderer: AppRenderer, config: ProxyConfig, parseRouteUrl: RouteUrlParser): import("connect").NextHandleFunction; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43671
621
12