From 530871e17c6549b544712ea4e793e7eb527a2a50 Mon Sep 17 00:00:00 2001 From: Artem Alexeyenko Date: Mon, 30 Jan 2023 13:49:53 -0500 Subject: [PATCH] [proxy] Disable websocket processing by default --- .../src/templates/node-headless-ssr-proxy/src/config.ts | 5 +++++ packages/sitecore-jss-proxy/src/ProxyConfig.ts | 4 ++++ packages/sitecore-jss-proxy/src/index.ts | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/src/config.ts b/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/src/config.ts index b54f04f5d1..d2606bf1e1 100644 --- a/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/src/config.ts +++ b/packages/create-sitecore-jss/src/templates/node-headless-ssr-proxy/src/config.ts @@ -88,6 +88,11 @@ export const config: ProxyConfig = { * Default: 10MB */ maxResponseSizeBytes: 10 * 1024 * 1024, + /** + * Enables or disables proxy handling WebSocket connections + * Disabled by default - default JSS proxy logic doesn't handle WS requests and extra implementation is needed for WS to be processed. + */ + ws: false, /** * Options object for http-proxy-middleware. Consult its docs. */ diff --git a/packages/sitecore-jss-proxy/src/ProxyConfig.ts b/packages/sitecore-jss-proxy/src/ProxyConfig.ts index c0d69a0011..04aa04d6d9 100644 --- a/packages/sitecore-jss-proxy/src/ProxyConfig.ts +++ b/packages/sitecore-jss-proxy/src/ProxyConfig.ts @@ -40,6 +40,10 @@ export interface ProxyConfig { * Mutually exclusive with pathRewriteExcludePredicate. */ pathRewriteExcludeRoutes?: string[]; + /** + * Turn WebSocket requests processing on or off + */ + ws?: boolean; /** * Function to determine if a given URL should be SSRed (return true), or passed through (return false) * Mutually exclusive with pathRewriteExcludeRoutes. diff --git a/packages/sitecore-jss-proxy/src/index.ts b/packages/sitecore-jss-proxy/src/index.ts index 2a54659485..ac6b342962 100644 --- a/packages/sitecore-jss-proxy/src/index.ts +++ b/packages/sitecore-jss-proxy/src/index.ts @@ -558,7 +558,7 @@ function createOptions( ...config.proxyOptions, target: config.apiHost, changeOrigin: true, // required otherwise need to include CORS headers - ws: true, + ws: config.ws || false, pathRewrite: (reqPath, req) => rewriteRequestPath(reqPath, req, config, parseRouteUrl), logLevel: config.debug ? 'debug' : 'info', onProxyReq: (proxyReq, req, res) =>