Skip to content

Commit

Permalink
fix: strf-8846 Send stencil-cli header to storefront api
Browse files Browse the repository at this point in the history
  • Loading branch information
jairo-bc committed Oct 13, 2021
1 parent e906508 commit 5e06753
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/stencil-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -131,6 +131,7 @@ class StencilStart {
variationIndex: this._themeConfigManager.variationIndex || 0,
useCache: cliOptions.cache,
themePath: this._themeConfigManager.themePath,
stencilCliVersion: PACKAGE_INFO.version,
});
}

Expand Down
1 change: 1 addition & 0 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 10 additions & 5 deletions server/plugins/router/router.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ internals.registerRoutes = (server) => {
protocol: 'https',
port: 443,
passThrough: true,
xforward: false,
},
},
options: {
Expand All @@ -112,12 +111,18 @@ 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: {
Expand Down

0 comments on commit 5e06753

Please sign in to comment.