From 15e12029b007932231a08ec218ea39cc2e671e4b Mon Sep 17 00:00:00 2001 From: Jon Wiese Date: Tue, 27 Feb 2024 09:12:04 -0700 Subject: [PATCH] fix: Properly add stencil-cli headers to internalapi requests --- server/plugins/router/router.module.js | 30 ++++++++++++-------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/server/plugins/router/router.module.js b/server/plugins/router/router.module.js index a79a59fc..d0eaf0c5 100644 --- a/server/plugins/router/router.module.js +++ b/server/plugins/router/router.module.js @@ -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); @@ -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, }, }, @@ -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, }, },