Skip to content

Commit

Permalink
fix: Properly add stencil-cli headers to internalapi requests (#1164)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmwiese authored Feb 27, 2024
2 parents 891b079 + 15e1202 commit 24ae309
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions server/plugins/router/router.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ const internals = {
},
};

function 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,
'x-auth-token': internals.options.accessToken,
};

return { uri, headers };
}

function register(server, options) {
internals.options = _.defaultsDeep(options, internals.options);

Expand Down Expand Up @@ -96,10 +108,8 @@ internals.registerRoutes = (server) => {
path: internals.paths.internalApi,
handler: {
proxy: {
host: internals.options.storeUrl.replace(/http[s]?:\/\//, ''),
mapUri,
rejectUnauthorized: false,
protocol: 'https',
port: 443,
passThrough: true,
},
},
Expand All @@ -114,20 +124,8 @@ internals.registerRoutes = (server) => {
path: internals.paths.storefrontAPI,
handler: {
proxy: {
mapUri,
rejectUnauthorized: false,
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,
'x-auth-token': internals.options.accessToken,
};
return { uri, headers };
},
passThrough: true,
},
},
Expand Down

0 comments on commit 24ae309

Please sign in to comment.