From da899b90e26d5ee393eefc302be985eb7c9055a5 Mon Sep 17 00:00:00 2001 From: Saad Jutt Date: Fri, 18 Feb 2022 07:25:48 +0500 Subject: [PATCH] fix: added http headers to /code api as well --- api/src/controllers/code.ts | 21 +++++++++++++-------- api/src/controllers/stp.ts | 4 ++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/api/src/controllers/code.ts b/api/src/controllers/code.ts index 939f098..a406a4d 100644 --- a/api/src/controllers/code.ts +++ b/api/src/controllers/code.ts @@ -30,15 +30,20 @@ export class CodeController { const executeSASCode = async (req: any, { code }: ExecuteSASCodePayload) => { try { - const { result } = (await new ExecutionController().executeProgram( - code, - getPreProgramVariables(req), - { ...req.query, _debug: 131 }, - undefined, - true - )) as ExecuteReturnRaw + const { result, httpHeaders } = + (await new ExecutionController().executeProgram( + code, + getPreProgramVariables(req), + { ...req.query, _debug: 131 }, + undefined, + true + )) as ExecuteReturnRaw - return result as string + Object.entries(httpHeaders).forEach(([key, value]) => { + req.res?.set(key, value) + }) + + return result } catch (err: any) { throw { code: 400, diff --git a/api/src/controllers/stp.ts b/api/src/controllers/stp.ts index 8d41315..add7c14 100644 --- a/api/src/controllers/stp.ts +++ b/api/src/controllers/stp.ts @@ -85,7 +85,7 @@ const executeReturnRaw = async ( query )) as ExecuteReturnRaw - Object.entries(httpHeaders ?? {}).forEach(([key, value]) => { + Object.entries(httpHeaders).forEach(([key, value]) => { req.res?.set(key, value) }) @@ -121,7 +121,7 @@ const executeReturnJson = async ( true )) as ExecuteReturnJson - Object.entries(httpHeaders ?? {}).forEach(([key, value]) => { + Object.entries(httpHeaders).forEach(([key, value]) => { req.res?.set(key, value) })