mirror of
https://github.com/sasjs/server.git
synced 2026-01-08 15:00:05 +00:00
fix(stp): return plain/text header for GET & debug
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
|||||||
generateFileUploadSasCode,
|
generateFileUploadSasCode,
|
||||||
getTmpFilesFolderPath,
|
getTmpFilesFolderPath,
|
||||||
HTTPHeaders,
|
HTTPHeaders,
|
||||||
|
isDebugOn,
|
||||||
sasJSCoreMacros
|
sasJSCoreMacros
|
||||||
} from '../../utils'
|
} from '../../utils'
|
||||||
|
|
||||||
@@ -160,9 +161,6 @@ ${program}`
|
|||||||
: await readFile(weboutPath)
|
: await readFile(weboutPath)
|
||||||
: ''
|
: ''
|
||||||
|
|
||||||
const debugValue =
|
|
||||||
typeof vars._debug === 'string' ? parseInt(vars._debug) : vars._debug
|
|
||||||
|
|
||||||
// it should be deleted by scheduleSessionDestroy
|
// it should be deleted by scheduleSessionDestroy
|
||||||
session.inUse = false
|
session.inUse = false
|
||||||
|
|
||||||
@@ -170,8 +168,7 @@ ${program}`
|
|||||||
return {
|
return {
|
||||||
httpHeaders,
|
httpHeaders,
|
||||||
webout,
|
webout,
|
||||||
log:
|
log: isDebugOn(vars) || session.crashed ? log : undefined
|
||||||
(debugValue && debugValue >= 131) || session.crashed ? log : undefined
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,7 +176,7 @@ ${program}`
|
|||||||
httpHeaders,
|
httpHeaders,
|
||||||
result: fileResponse
|
result: fileResponse
|
||||||
? webout
|
? webout
|
||||||
: (debugValue && debugValue >= 131) || session.crashed
|
: isDebugOn(vars) || session.crashed
|
||||||
? `<html><body>${webout}<div style="text-align:left"><hr /><h2>SAS Log</h2><pre>${log}</pre></div></body></html>`
|
? `<html><body>${webout}<div style="text-align:left"><hr /><h2>SAS Log</h2><pre>${log}</pre></div></body></html>`
|
||||||
: webout
|
: webout
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import { PreProgramVars } from '../types'
|
|||||||
import {
|
import {
|
||||||
getTmpFilesFolderPath,
|
getTmpFilesFolderPath,
|
||||||
HTTPHeaders,
|
HTTPHeaders,
|
||||||
|
isDebugOn,
|
||||||
LogLine,
|
LogLine,
|
||||||
makeFilesNamesMap,
|
makeFilesNamesMap,
|
||||||
parseLogToArray
|
parseLogToArray
|
||||||
@@ -62,7 +63,9 @@ export class STPController {
|
|||||||
* The response headers can be adjusted using the mfs_httpheader() macro. Any
|
* The response headers can be adjusted using the mfs_httpheader() macro. Any
|
||||||
* file type can be returned, including binary files such as zip or xls.
|
* file type can be returned, including binary files such as zip or xls.
|
||||||
*
|
*
|
||||||
* This behaviour differs for POST requests, in which case the reponse is
|
* If _debug is >= 131, response headers will contain Content-Type: 'text/plain'
|
||||||
|
*
|
||||||
|
* This behaviour differs for POST requests, in which case the response is
|
||||||
* always JSON.
|
* always JSON.
|
||||||
*
|
*
|
||||||
* @summary Execute Stored Program, return raw _webout content.
|
* @summary Execute Stored Program, return raw _webout content.
|
||||||
@@ -140,6 +143,13 @@ const executeReturnRaw = async (
|
|||||||
query
|
query
|
||||||
)) as ExecuteReturnRaw
|
)) as ExecuteReturnRaw
|
||||||
|
|
||||||
|
// Should over-ride response header for
|
||||||
|
// debug on GET request to see entire log
|
||||||
|
// rendering on browser.
|
||||||
|
if (isDebugOn(query)) {
|
||||||
|
httpHeaders['content-type'] = 'text/plain'
|
||||||
|
}
|
||||||
|
|
||||||
req.res?.set(httpHeaders)
|
req.res?.set(httpHeaders)
|
||||||
|
|
||||||
if (result instanceof Buffer) {
|
if (result instanceof Buffer) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ export * from './file'
|
|||||||
export * from './generateAccessToken'
|
export * from './generateAccessToken'
|
||||||
export * from './generateAuthCode'
|
export * from './generateAuthCode'
|
||||||
export * from './generateRefreshToken'
|
export * from './generateRefreshToken'
|
||||||
|
export * from './isDebugOn'
|
||||||
export * from './getCertificates'
|
export * from './getCertificates'
|
||||||
export * from './getDesktopFields'
|
export * from './getDesktopFields'
|
||||||
export * from './parseLogToArray'
|
export * from './parseLogToArray'
|
||||||
|
|||||||
8
api/src/utils/isDebugOn.ts
Normal file
8
api/src/utils/isDebugOn.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { ExecutionVars } from '../controllers/internal'
|
||||||
|
|
||||||
|
export const isDebugOn = (vars: ExecutionVars) => {
|
||||||
|
const debugValue =
|
||||||
|
typeof vars._debug === 'string' ? parseInt(vars._debug) : vars._debug
|
||||||
|
|
||||||
|
return !!(debugValue && debugValue >= 131)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user