@@ -20,6 +20,18 @@ const internals = {
2020 } ,
2121} ;
2222
23+ function mapUri ( req ) {
24+ const host = `https://${ internals . options . storeUrl . replace ( / h t t p [ 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+
2335function 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 ( / h t t p [ 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- / h t t p [ 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