Skip to content

Commit 24ae309

Browse files
authored
fix: Properly add stencil-cli headers to internalapi requests (#1164)
2 parents 891b079 + 15e1202 commit 24ae309

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

server/plugins/router/router.module.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ const internals = {
2020
},
2121
};
2222

23+
function mapUri(req) {
24+
const host = `https://${internals.options.storeUrl.replace(/http[s]?:\/\//, '')}`;
25+
const urlParams = req.url.search || '';
26+
const uri = `${host}${req.path}${urlParams}`;
27+
const headers = {
28+
'stencil-cli': internals.options.stencilCliVersion,
29+
'x-auth-token': internals.options.accessToken,
30+
};
31+
32+
return { uri, headers };
33+
}
34+
2335
function register(server, options) {
2436
internals.options = _.defaultsDeep(options, internals.options);
2537

@@ -96,10 +108,8 @@ internals.registerRoutes = (server) => {
96108
path: internals.paths.internalApi,
97109
handler: {
98110
proxy: {
99-
host: internals.options.storeUrl.replace(/http[s]?:\/\//, ''),
111+
mapUri,
100112
rejectUnauthorized: false,
101-
protocol: 'https',
102-
port: 443,
103113
passThrough: true,
104114
},
105115
},
@@ -114,20 +124,8 @@ internals.registerRoutes = (server) => {
114124
path: internals.paths.storefrontAPI,
115125
handler: {
116126
proxy: {
127+
mapUri,
117128
rejectUnauthorized: false,
118-
mapUri: (req) => {
119-
const host = `https://${internals.options.storeUrl.replace(
120-
/http[s]?:\/\//,
121-
'',
122-
)}`;
123-
const urlParams = req.url.search || '';
124-
const uri = `${host}${req.path}${urlParams}`;
125-
const headers = {
126-
'stencil-cli': internals.options.stencilCliVersion,
127-
'x-auth-token': internals.options.accessToken,
128-
};
129-
return { uri, headers };
130-
},
131129
passThrough: true,
132130
},
133131
},

0 commit comments

Comments
 (0)