@@ -91,14 +91,34 @@ function del(url, data) {
9191 } ) ;
9292}
9393
94- function escape ( text ) {
95- return encodeURIComponent ( text ) ;
94+ function escape ( text , key ) {
95+ let escapedText = "" ;
96+ if ( Array . isArray ( text ) ) {
97+ for ( let i = 0 ; i < text . length ; i ++ ) {
98+ if ( i > 0 ) {
99+ escapedText += "&" + key + "=" ;
100+ }
101+ escapedText += encodeURIComponent ( text [ i ] ) ;
102+ }
103+ } else {
104+ escapedText = encodeURIComponent ( text ) ;
105+ }
106+ return escapedText ;
96107}
97108
98109function stringifySafe ( obj , replacer , spaces , cycleReplacer ) {
99110 return JSON . stringify ( obj , serializer ( replacer , cycleReplacer ) , spaces )
100111}
101112
113+ function filterError ( origError ) {
114+ if ( origError . response !== undefined ) {
115+ // remove config & request data, because it contains sensitive data.
116+ origError . response . config = null ;
117+ origError . response . request = null ;
118+ }
119+ return origError ;
120+ }
121+
102122function serializer ( replacer , cycleReplacer ) {
103123 var stack = [ ] , keys = [ ]
104124
@@ -120,6 +140,15 @@ function serializer(replacer, cycleReplacer) {
120140 }
121141}
122142
143+ app . get ( '/testdata' , function ( req , res ) {
144+ res . send ( "TEST DATA FROM BACKEND" ) ;
145+ } ) ;
146+
147+ app . post ( '/testdata' , function ( req , res ) {
148+ console . log ( ">>> TEST DATA RECEIVED: " , req . body ) ;
149+ res . send ( "OK" ) ;
150+ } ) ;
151+
123152app . get ( '/' , function ( req , res ) {
124153 res . sendFile ( vuePath + "index.html" ) ;
125154} ) ;
@@ -128,17 +157,18 @@ app.post('/', (req, res) => {
128157 let call = req . body . url ;
129158 let i = 0 ;
130159 for ( let key in req . body . params ) {
131- if ( i == 0 ) {
132- call += "?" + key + "=" + escape ( req . body . params [ key ] ) ;
160+ if ( i === 0 ) {
161+ call += "?" + key + "=" + escape ( req . body . params [ key ] , key ) ;
133162 } else {
134- call += "&" + key + "=" + escape ( req . body . params [ key ] ) ;
163+ call += "&" + key + "=" + escape ( req . body . params [ key ] , key ) ;
135164 }
136165 i ++ ;
137166 }
138167 if ( req . body . type == "POST" ) {
139168 post ( connectorUrl + call , req . body . body ) . then ( response => {
140169 res . send ( response . data ) ;
141- } ) . catch ( error => {
170+ } ) . catch ( origError => {
171+ let error = filterError ( origError ) ;
142172 if ( error . response === undefined ) {
143173 console . log ( "Error on POST " + req . body . url , error ) ;
144174 res . send ( stringifySafe ( error ) ) ;
@@ -151,7 +181,8 @@ app.post('/', (req, res) => {
151181 } else if ( req . body . type == "PUT" ) {
152182 put ( connectorUrl + call , req . body . body ) . then ( response => {
153183 res . send ( response . data ) ;
154- } ) . catch ( error => {
184+ } ) . catch ( origError => {
185+ let error = filterError ( origError ) ;
155186 if ( error . response === undefined ) {
156187 console . log ( "Error on PUT " + req . body . url , error ) ;
157188 res . send ( stringifySafe ( error ) ) ;
@@ -166,7 +197,8 @@ app.post('/', (req, res) => {
166197 } else {
167198 get ( connectorUrl + call ) . then ( response => {
168199 res . send ( response . data ) ;
169- } ) . catch ( error => {
200+ } ) . catch ( origError => {
201+ let error = filterError ( origError ) ;
170202 if ( error . response === undefined ) {
171203 console . log ( "Error on GET " + req . body . url , error ) ;
172204 res . send ( stringifySafe ( error ) ) ;
@@ -179,7 +211,8 @@ app.post('/', (req, res) => {
179211 } else if ( req . body . type == "DELETE" ) {
180212 del ( connectorUrl + call , req . body . body ) . then ( response => {
181213 res . send ( response . data ) ;
182- } ) . catch ( error => {
214+ } ) . catch ( origError => {
215+ let error = filterError ( origError ) ;
183216 if ( error . response === undefined ) {
184217 console . log ( "Error on DELETE " + req . body . url , error ) ;
185218 res . send ( stringifySafe ( error ) ) ;
0 commit comments