From 29d165261d34217ce5de563c4e2648e6e3bb1d83 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 7 May 2024 14:51:39 -0700 Subject: [PATCH] Added response headers to proxied response so that the front end can handle content-encoding. Also added a 500 response code when the response doesnt exist --- server/server.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/server/server.js b/server/server.js index f90d50b..44d2158 100644 --- a/server/server.js +++ b/server/server.js @@ -102,7 +102,11 @@ app.use('/api/v1/brokerPath/', (req, res, next) => { res.status(resp.status).send(JSON.stringify(resp.data)) }).catch((error) => { console.error(error); - res.status(error.response.status).send(error.response.data) + if(error.response){ + res.status(error.response.status).send(error.response.data) + }else{ + res.status(500).send(error.response?.data) + } }) }) @@ -148,6 +152,11 @@ const onProxyRes = (proxyRes, req, res) => { cfg.L.warn('proxy request failed with status ' + proxyRes.statusCode + ', url: \'' + proxyRes.req.host + proxyRes.req.path + '\'') } + // set the response headers so that the frontend can decode the content + Object.keys(proxyRes.headers).forEach((key) => { + res.setHeader(key, proxyRes.headers[key]); + }); + if (proxyRes?.headers?.location) { const headers = req.headers; const body = req.body;