From 47840c2d84ab2ad49c729dd0b7446451fcbf1807 Mon Sep 17 00:00:00 2001 From: Jairo Panduro Date: Wed, 13 Oct 2021 18:27:05 +0300 Subject: [PATCH] fix: strf-8846 Send stencil-cli header to storefront api --- lib/stencil-start.js | 3 ++- server/index.js | 1 + server/plugins/router/router.module.js | 12 +++++++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/stencil-start.js b/lib/stencil-start.js index 057befff3..daf601c70 100755 --- a/lib/stencil-start.js +++ b/lib/stencil-start.js @@ -5,7 +5,7 @@ const path = require('path'); const Cycles = require('./Cycles'); const templateAssemblerModule = require('./template-assembler'); -const { THEME_PATH } = require('../constants'); +const { PACKAGE_INFO, THEME_PATH } = require('../constants'); const Server = require('../server'); const StencilConfigManager = require('./StencilConfigManager'); const ThemeConfig = require('./theme-config'); @@ -131,6 +131,7 @@ class StencilStart { variationIndex: this._themeConfigManager.variationIndex || 0, useCache: cliOptions.cache, themePath: this._themeConfigManager.themePath, + stencilCliVersion: PACKAGE_INFO.version, }); } diff --git a/server/index.js b/server/index.js index 44240ed2f..2857ce1e0 100644 --- a/server/index.js +++ b/server/index.js @@ -19,6 +19,7 @@ function buildManifest(srcManifest, options) { parsedNormalUrl.protocol + '//' + parsedNormalUrl.host; pluginsByName['./plugins/router/router.module'].apiKey = options.dotStencilFile.apiKey; pluginsByName['./plugins/router/router.module'].port = options.dotStencilFile.port; + pluginsByName['./plugins/router/router.module'].stencilCliVersion = options.stencilCliVersion; pluginsByName['./plugins/renderer/renderer.module'].useCache = options.useCache; pluginsByName['./plugins/renderer/renderer.module'].username = options.dotStencilFile.username; pluginsByName['./plugins/renderer/renderer.module'].token = options.dotStencilFile.token; diff --git a/server/plugins/router/router.module.js b/server/plugins/router/router.module.js index 72439ba19..8b7936f5b 100644 --- a/server/plugins/router/router.module.js +++ b/server/plugins/router/router.module.js @@ -98,7 +98,6 @@ internals.registerRoutes = (server) => { protocol: 'https', port: 443, passThrough: true, - xforward: false, }, }, options: { @@ -112,12 +111,15 @@ internals.registerRoutes = (server) => { path: internals.paths.storefrontAPI, handler: { proxy: { - host: internals.options.storeUrl.replace(/http[s]?:\/\//, ''), rejectUnauthorized: false, - protocol: 'https', - port: 443, + mapUri: (req) => { + const host = `https://${internals.options.storeUrl.replace(/http[s]?:\/\//, '')}`; + const urlParams = req.url.search || ''; + const uri = `${host}${req.path}${urlParams}`; + const headers = { 'stencil-cli': internals.options.stencilCliVersion }; + return { uri, headers }; + }, passThrough: true, - xforward: false, }, }, options: {