@sitecore-jss/sitecore-jss-proxy
Advanced tools
Comparing version 10.0.0-preview.1 to 11.0.0-alpha.0
"use strict"; | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
return t; | ||
}; | ||
@@ -41,139 +79,200 @@ var __importDefault = (this && this.__importDefault) || function (mod) { | ||
function renderAppToResponse(proxyResponse, request, serverResponse, renderer, config) { | ||
// monkey-patch FTW? | ||
var originalWriteHead = serverResponse.writeHead; | ||
var originalWrite = serverResponse.write; | ||
var originalEnd = serverResponse.end; | ||
// these lines are necessary and must happen before we do any writing to the response | ||
// otherwise the headers will have already been sent | ||
delete proxyResponse.headers['content-length']; | ||
proxyResponse.headers['content-type'] = 'text/html; charset=utf-8'; | ||
// remove IIS server header for security | ||
delete proxyResponse.headers['server']; | ||
if (config.setHeaders) { | ||
config.setHeaders(request, serverResponse, proxyResponse); | ||
} | ||
var contentEncoding = proxyResponse.headers['content-encoding']; | ||
if (contentEncoding && | ||
(contentEncoding.indexOf('gzip') !== -1 || contentEncoding.indexOf('deflate') !== -1)) { | ||
delete proxyResponse.headers['content-encoding']; | ||
} | ||
// we are going to set our own status code if rendering fails | ||
serverResponse.writeHead = function () { }; | ||
// buffer the response body as it is written for later processing | ||
var buf = Buffer.from(''); | ||
serverResponse.write = function (data, encoding) { | ||
if (Buffer.isBuffer(data)) { | ||
buf = Buffer.concat([buf, data]); // append raw buffer | ||
return __awaiter(this, void 0, void 0, function () { | ||
function extractLayoutServiceDataFromProxyResponse() { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var responseString; | ||
return __generator(this, function (_a) { | ||
if (proxyResponse.statusCode === 200 || proxyResponse.statusCode === 404) { | ||
responseString = void 0; | ||
if (contentEncoding && | ||
(contentEncoding.indexOf('gzip') !== -1 || contentEncoding.indexOf('deflate') !== -1)) { | ||
responseString = new Promise(function (resolve, reject) { | ||
if (config.debug) { | ||
console.log('Layout service response is compressed; decompressing.'); | ||
} | ||
zlib_1.default.unzip(buf, function (error, result) { | ||
if (error) { | ||
reject(error); | ||
} | ||
if (result) { | ||
resolve(result.toString('utf-8')); | ||
} | ||
}); | ||
}); | ||
} | ||
else { | ||
responseString = Promise.resolve(buf.toString('utf-8')); | ||
} | ||
return [2 /*return*/, responseString.then(util_1.tryParseJson)]; | ||
} | ||
return [2 /*return*/, Promise.resolve(null)]; | ||
}); | ||
}); | ||
} | ||
else { | ||
buf = Buffer.concat([buf, Buffer.from(data, encoding)]); // append string with optional character encoding (default utf8) | ||
// function replies with HTTP 500 when an error occurs | ||
function replyWithError(error) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var errorResponse, onError; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
console.error(error); | ||
errorResponse = { | ||
statusCode: proxyResponse.statusCode || 500, | ||
content: proxyResponse.statusMessage || 'Internal Server Error', | ||
}; | ||
if (!config.onError) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, config.onError(error, proxyResponse)]; | ||
case 1: | ||
onError = _a.sent(); | ||
errorResponse = __assign({}, errorResponse, onError); | ||
_a.label = 2; | ||
case 2: | ||
completeProxyResponse(Buffer.from(errorResponse.content), errorResponse.statusCode, {}); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
// sanity check: if the response is huge, bail. | ||
// ...we don't want to let someone bring down the server by filling up all our RAM. | ||
if (buf.length > config.maxResponseSizeBytes) { | ||
throw new Error('Document too large'); | ||
} | ||
return true; | ||
}; | ||
// as the response is ending, we parse the current response body which is JSON, then | ||
// render the app using that JSON, but return HTML to the final response. | ||
serverResponse.end = function () { | ||
// js object of LS response JSON - or null, if LS has an error or not found | ||
var layoutServiceData = Promise.resolve(null); | ||
// for successful status code results, we need to parse the body | ||
// (layout service does not return details of 500 results) | ||
if (proxyResponse.statusCode === 200 || proxyResponse.statusCode === 404) { | ||
var responseString = void 0; | ||
if (contentEncoding && | ||
(contentEncoding.indexOf('gzip') !== -1 || contentEncoding.indexOf('deflate') !== -1)) { | ||
responseString = new Promise(function (resolve, reject) { | ||
if (config.debug) { | ||
console.log('Layout service response is compressed; decompressing.'); | ||
// callback handles the result of server-side rendering | ||
function handleRenderingResult(error, result) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _a, content, finalStatusCode; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (!error && !result) { | ||
return [2 /*return*/, replyWithError(new Error('Render function did not return a result or an error!'))]; | ||
} | ||
if (error) { | ||
return [2 /*return*/, replyWithError(error)]; | ||
} | ||
if (!result) { | ||
// should not occur, but makes TS happy | ||
return [2 /*return*/, replyWithError(new Error('Render function result did not return a result.'))]; | ||
} | ||
if (!result.html) { | ||
return [2 /*return*/, replyWithError(new Error('Render function result was returned but html property was falsy.'))]; | ||
} | ||
if (!config.transformSSRContent) return [3 /*break*/, 2]; | ||
_a = result; | ||
return [4 /*yield*/, config.transformSSRContent(result, request, serverResponse)]; | ||
case 1: | ||
_a.html = _b.sent(); | ||
_b.label = 2; | ||
case 2: | ||
content = Buffer.from(result.html); | ||
// setting the content-length header is not absolutely necessary, but is recommended | ||
proxyResponse.headers['content-length'] = content.length.toString(10); | ||
if (result.redirect) { | ||
if (!result.status) { | ||
result.status = 302; | ||
} | ||
proxyResponse.headers['location'] = result.redirect; | ||
} | ||
finalStatusCode = result.status || proxyResponse.statusCode || 200; | ||
if (config.debug) { | ||
console.log('DEBUG: FINAL response headers for client', JSON.stringify(proxyResponse.headers, null, 2)); | ||
console.log('DEBUG: FINAL status code for client', finalStatusCode); | ||
} | ||
completeProxyResponse(content, finalStatusCode); | ||
return [2 /*return*/]; | ||
} | ||
zlib_1.default.unzip(buf, function (error, result) { | ||
if (error) { | ||
reject(error); | ||
} | ||
if (result) { | ||
resolve(result.toString('utf-8')); | ||
} | ||
}); | ||
}); | ||
} | ||
else { | ||
responseString = Promise.resolve(buf.toString('utf-8')); | ||
} | ||
layoutServiceData = responseString.then(util_1.tryParseJson); | ||
}); | ||
} | ||
// function replies with HTTP 500 when an error occurs | ||
var replyWithError = function (error) { | ||
console.error(error); | ||
var errorResponse = { | ||
statusCode: proxyResponse.statusCode || 500, | ||
content: proxyResponse.statusMessage || 'Internal Server Error', | ||
}; | ||
if (config.onError) { | ||
errorResponse = __assign({}, errorResponse, config.onError(error, proxyResponse)); | ||
function completeProxyResponse(content, statusCode, headers) { | ||
if (!headers) { | ||
headers = proxyResponse.headers; | ||
} | ||
originalWriteHead.apply(serverResponse, [errorResponse.statusCode, {}]); | ||
originalWrite.call(serverResponse, Buffer.from(errorResponse.content)); | ||
originalWriteHead.apply(serverResponse, [statusCode, headers]); | ||
originalWrite.call(serverResponse, content); | ||
originalEnd.call(serverResponse); | ||
}; | ||
// callback that handles the result from the render function | ||
var handleResult = function (error, result) { | ||
if (!error && !result) { | ||
replyWithError(new Error('Render function did not return a result or an error!')); | ||
} | ||
function createViewBag(layoutServiceData) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var viewBag, customViewBag; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
viewBag = { | ||
statusCode: proxyResponse.statusCode, | ||
dictionary: {}, | ||
}; | ||
if (!config.createViewBag) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, config.createViewBag(request, serverResponse, proxyResponse, layoutServiceData)]; | ||
case 1: | ||
customViewBag = _a.sent(); | ||
viewBag = __assign({}, viewBag, customViewBag); | ||
_a.label = 2; | ||
case 2: return [2 /*return*/, viewBag]; | ||
} | ||
}); | ||
}); | ||
} | ||
var originalWriteHead, originalWrite, originalEnd, contentEncoding, buf; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
originalWriteHead = serverResponse.writeHead; | ||
originalWrite = serverResponse.write; | ||
originalEnd = serverResponse.end; | ||
// these lines are necessary and must happen before we do any writing to the response | ||
// otherwise the headers will have already been sent | ||
delete proxyResponse.headers['content-length']; | ||
proxyResponse.headers['content-type'] = 'text/html; charset=utf-8'; | ||
// remove IIS server header for security | ||
delete proxyResponse.headers['server']; | ||
if (config.setHeaders) { | ||
config.setHeaders(request, serverResponse, proxyResponse); | ||
} | ||
if (error) { | ||
replyWithError(error); | ||
return; | ||
contentEncoding = proxyResponse.headers['content-encoding']; | ||
if (contentEncoding && | ||
(contentEncoding.indexOf('gzip') !== -1 || contentEncoding.indexOf('deflate') !== -1)) { | ||
delete proxyResponse.headers['content-encoding']; | ||
} | ||
if (!result) { | ||
// should not occur, but makes TS happy | ||
replyWithError(new Error('Render function result did not return a result.')); | ||
return; | ||
} | ||
if (!result.html) { | ||
replyWithError(new Error('Render function result was returned but html property was falsy.')); | ||
return; | ||
} | ||
if (config.transformSSRContent) { | ||
result.html = config.transformSSRContent(result, request, serverResponse); | ||
} | ||
// we have to convert back to a buffer so that we can get the *byte count* (rather than character count) of the body | ||
var content = Buffer.from(result.html); | ||
// setting the content-length header is not absolutely necessary, but is recommended | ||
proxyResponse.headers['content-length'] = content.length.toString(10); | ||
if (result.redirect) { | ||
if (!result.status) { | ||
result.status = 302; | ||
// we are going to set our own status code if rendering fails | ||
serverResponse.writeHead = function () { }; | ||
buf = Buffer.from(''); | ||
serverResponse.write = function (data, encoding) { | ||
if (Buffer.isBuffer(data)) { | ||
buf = Buffer.concat([buf, data]); // append raw buffer | ||
} | ||
proxyResponse.headers['location'] = result.redirect; | ||
} | ||
var finalStatusCode = result.status || proxyResponse.statusCode; | ||
if (config.debug) { | ||
console.log('FINAL response headers for output', JSON.stringify(proxyResponse.headers, null, 2)); | ||
console.log('FINAL status code', finalStatusCode); | ||
} | ||
originalWriteHead.apply(serverResponse, [finalStatusCode, proxyResponse.headers]); | ||
originalWrite.call(serverResponse, content); | ||
originalEnd.call(serverResponse); | ||
}; | ||
var viewBag = { | ||
statusCode: proxyResponse.statusCode, | ||
dictionary: {}, | ||
}; | ||
if (config.createViewBag) { | ||
viewBag = __assign({}, config.createViewBag(request, serverResponse, proxyResponse), viewBag); | ||
} | ||
layoutServiceData | ||
.then(function (data) { | ||
if (!data) { | ||
throw new Error("Received invalid response " + proxyResponse.statusCode + " " + proxyResponse.statusMessage); | ||
} | ||
return data; | ||
}) | ||
.then(function (data) { return renderer(handleResult, request.originalUrl, data, viewBag); }) | ||
.catch(replyWithError); | ||
}; | ||
else { | ||
buf = Buffer.concat([buf, Buffer.from(data, encoding)]); // append string with optional character encoding (default utf8) | ||
} | ||
// sanity check: if the response is huge, bail. | ||
// ...we don't want to let someone bring down the server by filling up all our RAM. | ||
if (buf.length > config.maxResponseSizeBytes) { | ||
throw new Error('Document too large'); | ||
} | ||
return true; | ||
}; | ||
// as the response is ending, we parse the current response body which is JSON, then | ||
// render the app using that JSON, but return HTML to the final response. | ||
serverResponse.end = function () { return __awaiter(_this, void 0, void 0, function () { | ||
var layoutServiceData, viewBag, error_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 3, , 4]); | ||
return [4 /*yield*/, extractLayoutServiceDataFromProxyResponse()]; | ||
case 1: | ||
layoutServiceData = _a.sent(); | ||
return [4 /*yield*/, createViewBag(layoutServiceData)]; | ||
case 2: | ||
viewBag = _a.sent(); | ||
if (!layoutServiceData) { | ||
throw new Error("Received invalid response " + proxyResponse.statusCode + " " + proxyResponse.statusMessage); | ||
} | ||
return [2 /*return*/, renderer(handleRenderingResult, request.originalUrl, layoutServiceData, viewBag)]; | ||
case 3: | ||
error_1 = _a.sent(); | ||
return [2 /*return*/, replyWithError(error_1)]; | ||
case 4: return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
return [2 /*return*/]; | ||
}); | ||
}); | ||
} | ||
@@ -183,23 +282,27 @@ function handleProxyResponse(proxyResponse, request, serverResponse, renderer, config) { | ||
if (config.debug) { | ||
console.log('request url', request.url); | ||
console.log('request query', request.query); | ||
console.log('request original url', request.originalUrl); | ||
console.log('response code', proxyResponse.statusCode); | ||
console.log('RAW request headers', JSON.stringify(request.headers, null, 2)); | ||
console.log('RAW response headers from the target', JSON.stringify(proxyResponse.headers, null, 2)); | ||
console.log('DEBUG: request url', request.url); | ||
console.log('DEBUG: request query', request.query); | ||
console.log('DEBUG: request original url', request.originalUrl); | ||
console.log('DEBUG: proxied request response code', proxyResponse.statusCode); | ||
console.log('DEBUG: RAW request headers', JSON.stringify(request.headers, null, 2)); | ||
console.log('DEBUG: RAW headers from the proxied response', JSON.stringify(proxyResponse.headers, null, 2)); | ||
} | ||
// if the request URL contains any of the excluded rewrite routes, we assume the response does not need to be server rendered. | ||
// instead, the response should just be relayed as usual. | ||
if (config.pathRewriteExcludeRoutes.find(function (r) { return request.originalUrl.indexOf(r) !== -1; })) { | ||
return; | ||
if (isUrlIgnored(request.originalUrl, config, true)) { | ||
return Promise.resolve(undefined); | ||
} | ||
// your first thought might be: why do we need to render the app here? why not just pass the JSON response to another piece of middleware that will render the app? | ||
// the answer: the proxy middleware ends the response and does not "chain" | ||
renderAppToResponse(proxyResponse, request, serverResponse, renderer, config); | ||
return renderAppToResponse(proxyResponse, request, serverResponse, renderer, config); | ||
} | ||
function rewriteRequestPath(reqPath, req, config, parseRouteUrl) { | ||
// necessary to make sure proxy doesn't fail if target server sends gzipped | ||
// delete req.headers['accept-encoding']; | ||
// the path comes in URL-encoded by default, | ||
// but we don't want that because... | ||
// 1. We need to URL-encode it before we send it out to the Layout Service, if it matches a route | ||
// 2. We don't want to force people to URL-encode ignored routes, etc (just use spaces instead of %20, etc) | ||
var decodedReqPath = decodeURIComponent(reqPath); | ||
// if the request URL contains a path/route that should not be re-written, then just pass it along as-is | ||
if (config.pathRewriteExcludeRoutes.find(function (r) { return reqPath.indexOf(r) !== -1; })) { | ||
if (isUrlIgnored(decodedReqPath, config)) { | ||
// we do not return the decoded URL because we're using it verbatim - should be encoded. | ||
return reqPath; | ||
@@ -209,7 +312,7 @@ } | ||
// if this seems redundant, it is. the config.pathRewriteExcludeRoutes should contain the layout service path, but can't always assume that it will... | ||
if (reqPath.indexOf(config.layoutServiceRoute) !== -1) { | ||
if (decodedReqPath.indexOf(config.layoutServiceRoute) !== -1) { | ||
return reqPath; | ||
} | ||
var finalReqPath = reqPath; | ||
var qsIndex = reqPath.indexOf('?'); | ||
var finalReqPath = decodedReqPath; | ||
var qsIndex = finalReqPath.indexOf('?'); | ||
var qs; | ||
@@ -222,3 +325,6 @@ if (qsIndex > -1) { | ||
if (parseRouteUrl) { | ||
var routeParams = parseRouteUrl(reqPath); | ||
if (config.debug) { | ||
console.log("DEBUG: Parsing route URL using " + decodedReqPath + " URL..."); | ||
} | ||
var routeParams = parseRouteUrl(decodedReqPath); | ||
if (routeParams) { | ||
@@ -235,2 +341,5 @@ if (routeParams.sitecoreRoute) { | ||
lang = routeParams.lang; | ||
if (config.debug) { | ||
console.log("DEBUG: parseRouteUrl() result", routeParams); | ||
} | ||
} | ||
@@ -248,2 +357,32 @@ } | ||
exports.rewriteRequestPath = rewriteRequestPath; | ||
function isUrlIgnored(originalUrl, config, noDebug) { | ||
if (noDebug === void 0) { noDebug = false; } | ||
if (config.pathRewriteExcludePredicate && config.pathRewriteExcludeRoutes) { | ||
console.error('ERROR: pathRewriteExcludePredicate and pathRewriteExcludeRoutes were both provided in config. Provide only one.'); | ||
process.exit(1); | ||
} | ||
var result = null; | ||
if (config.pathRewriteExcludeRoutes) { | ||
var matchRoute_1 = decodeURIComponent(originalUrl).toUpperCase(); | ||
result = config.pathRewriteExcludeRoutes.find(function (excludedRoute) { return excludedRoute.length > 0 && matchRoute_1.startsWith(excludedRoute); }); | ||
if (!noDebug && config.debug && result) { | ||
console.log("DEBUG: URL " + originalUrl + " did not match the proxy exclude list, and will be treated as a layout service route to render. Excludes:", config.pathRewriteExcludeRoutes); | ||
} | ||
else if (!noDebug) { | ||
console.log("DEBUG: URL " + originalUrl + " matched the proxy exclude list and will be served verbatim as received. Excludes: ", config.pathRewriteExcludeRoutes); | ||
} | ||
return result ? true : false; | ||
} | ||
if (config.pathRewriteExcludePredicate) { | ||
result = config.pathRewriteExcludePredicate(originalUrl); | ||
if (config.debug && result) { | ||
console.log("DEBUG: URL " + originalUrl + " did not match the proxy exclude function, and will be treated as a layout service route to render."); | ||
} | ||
else { | ||
console.log("DEBUG: URL " + originalUrl + " matched the proxy exclude function and will be served verbatim as received."); | ||
} | ||
return result; | ||
} | ||
return false; | ||
} | ||
function createOptions(renderer, config, parseRouteUrl) { | ||
@@ -253,2 +392,11 @@ if (!config.maxResponseSizeBytes) { | ||
} | ||
// ensure all excludes are case insensitive | ||
if (config.pathRewriteExcludeRoutes && Array.isArray(config.pathRewriteExcludeRoutes)) { | ||
config.pathRewriteExcludeRoutes = config.pathRewriteExcludeRoutes.map(function (exclude) { | ||
return exclude.toUpperCase(); | ||
}); | ||
} | ||
if (config.debug) { | ||
console.log('DEBUG: Final proxy config', config); | ||
} | ||
return __assign({ target: config.apiHost, changeOrigin: true, ws: true, pathRewrite: function (reqPath, req) { return rewriteRequestPath(reqPath, req, config, parseRouteUrl); }, logLevel: config.debug ? 'debug' : 'info', onProxyRes: function (proxyRes, req, res) { return handleProxyResponse(proxyRes, req, res, renderer, config); } }, config.proxyOptions); | ||
@@ -255,0 +403,0 @@ } |
{ | ||
"name": "@sitecore-jss/sitecore-jss-proxy", | ||
"version": "10.0.0-preview.1", | ||
"version": "11.0.0-alpha.0", | ||
"description": "Proxy middleware for express.js server.", | ||
@@ -21,3 +21,3 @@ "main": "dist/index.js", | ||
}, | ||
"license": "SEE LICENSE IN LICENSE.MD", | ||
"license": "Apache-2.0", | ||
"homepage": "https://jss.sitecore.net", | ||
@@ -28,20 +28,20 @@ "bugs": { | ||
"dependencies": { | ||
"http-proxy-middleware": "0.18.0", | ||
"set-cookie-parser": "^2.1.1" | ||
"http-proxy-middleware": "^0.19.0", | ||
"set-cookie-parser": "^2.2.1" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.1.3", | ||
"@types/http-proxy-middleware": "^0.17.4", | ||
"@types/mocha": "^5.2.0", | ||
"@types/node": "^9.6.1", | ||
"@types/set-cookie-parser": "^0.0.2", | ||
"chai": "^4.1.2", | ||
"@types/chai": "^4.1.6", | ||
"@types/http-proxy-middleware": "^0.17.5", | ||
"@types/mocha": "^5.2.5", | ||
"@types/node": "^10.12.0", | ||
"@types/set-cookie-parser": "^0.0.3", | ||
"chai": "^4.2.0", | ||
"del-cli": "^1.1.0", | ||
"mocha": "^5.0.5", | ||
"sinon": "^4.5.0", | ||
"ts-node": "^5.0.1", | ||
"typescript": "^2.8.1" | ||
"mocha": "^5.2.0", | ||
"sinon": "^7.0.0", | ||
"ts-node": "^7.0.1", | ||
"typescript": "^3.1.3" | ||
}, | ||
"types": "types/index.d.ts", | ||
"gitHead": "dead320dec4c4c5444972a89aee2b86dd83f93d3" | ||
"gitHead": "96e06d70e432a4d530450f3955247f5a037c6295" | ||
} |
@@ -1,3 +0,2 @@ | ||
/// <reference types="node" /> | ||
import { IncomingMessage, ServerResponse } from 'http'; | ||
/// <reference types="connect" /> | ||
import { AppRenderer } from './AppRenderer'; | ||
@@ -8,2 +7,2 @@ import { ProxyConfig } from './ProxyConfig'; | ||
export declare function rewriteRequestPath(reqPath: string, req: any, config: ProxyConfig, parseRouteUrl?: RouteUrlParser): string; | ||
export default function scProxy(renderer: AppRenderer, config: ProxyConfig, parseRouteUrl: RouteUrlParser): (req: IncomingMessage, res: ServerResponse, next: (err?: any) => void) => void; | ||
export default function scProxy(renderer: AppRenderer, config: ProxyConfig, parseRouteUrl: RouteUrlParser): import("connect").NextHandleFunction; |
/// <reference types="node" /> | ||
import { IncomingMessage, ServerRequest, ServerResponse } from 'http'; | ||
import { ClientRequest, IncomingMessage, ServerResponse } from 'http'; | ||
import { Config as HttpProxyConfig } from 'http-proxy-middleware'; | ||
@@ -12,4 +12,13 @@ import { RenderResponse } from './RenderResponse'; | ||
apiKey: string; | ||
/** Array of paths to proxy without any SSR transformation (i.e. do not treat as app routes) */ | ||
pathRewriteExcludeRoutes: string[]; | ||
/** | ||
* Array of paths to proxy without any SSR transformation (i.e. do not treat as app routes). | ||
* Note: exclusions are case-insensitive. | ||
* Mutually exclusive with pathRewriteExcludePredicate. | ||
*/ | ||
pathRewriteExcludeRoutes?: string[]; | ||
/** | ||
* Function to determine if a given URL should be SSRed (return true), or passed through (return false) | ||
* Mutually exclusive with pathRewriteExcludeRoutes. | ||
*/ | ||
pathRewriteExcludePredicate?: (originalUrl: string) => boolean; | ||
/** Configure `http-proxy-middleware` */ | ||
@@ -20,14 +29,14 @@ proxyOptions?: HttpProxyConfig; | ||
/** Callback when an exception is thrown during SSR; decides what to send back to client (500 errors) */ | ||
onError?: (error: Error, response: IncomingMessage) => { | ||
onError?: (error: Error, response: IncomingMessage) => Promise<{ | ||
statusCode?: number; | ||
content?: string; | ||
}; | ||
}>; | ||
/** Enables transforming SSR'ed HTML after it is rendered, i.e. to replace paths. */ | ||
transformSSRContent?: (response: RenderResponse, request: ServerRequest, serverResponse: ServerResponse) => string; | ||
transformSSRContent?: (response: RenderResponse, request: ClientRequest, serverResponse: ServerResponse) => Promise<string>; | ||
/** Hook to fill the SSR viewBag object; if you're customizing the viewBag in Sitecore integrated SSR mode, do the same here. */ | ||
createViewBag?: (request: ServerRequest, response: ServerResponse, proxyResponse: IncomingMessage) => object; | ||
createViewBag?: (request: ClientRequest, response: ServerResponse, proxyResponse: IncomingMessage, layoutServiceData: any) => Promise<object>; | ||
/** Hook to alter HTTP headers in a custom way. */ | ||
setHeaders?: (request: ServerRequest, response: ServerResponse, proxyResponse: IncomingMessage) => void; | ||
setHeaders?: (request: ClientRequest, response: ServerResponse, proxyResponse: IncomingMessage) => void; | ||
/** Responses from the proxy greater than this size (in bytes) are rejected. */ | ||
maxResponseSizeBytes?: number; | ||
} |
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
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
39846
0
0
100
504
15
+ Addedhttp-proxy-middleware@0.19.2(transitive)
- Removedhttp-proxy-middleware@0.18.0(transitive)
Updatedset-cookie-parser@^2.2.1