1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-13 04:14:36 +00:00

fix: reqHeadrs.txt will contain headers to access APIs

This commit is contained in:
Saad Jutt
2022-05-08 02:49:16 +05:00
parent 25dc5dd215
commit 636301e664
7 changed files with 31 additions and 32 deletions

View File

@@ -0,0 +1,23 @@
import { PreProgramVars } from '../types'
export const getPreProgramVariables = (req: any): PreProgramVars => {
const host = req.get('host')
const protocol = req.protocol + '://'
const { user, accessToken } = req
const csrfToken = req.headers['x-xsrf-token']
const sessionId = req.cookies['connect.sid']
const httpHeaders: string[] = []
if (accessToken) httpHeaders.push(`Authorization: Bearer ${accessToken}`)
if (csrfToken) httpHeaders.push(`x-xsrf-token: ${csrfToken}`)
if (sessionId) httpHeaders.push(`cookie: connect.sid=${sessionId}`)
return {
username: user.username,
userId: user.userId,
displayName: user.displayName,
serverUrl: protocol + host,
httpHeaders
}
}