Skip to content

Commit

Permalink
feat(lib-util): add helper for constructing request headers
Browse files Browse the repository at this point in the history
  • Loading branch information
bytrangle committed Oct 11, 2021
1 parent 8436443 commit 3edc3ce
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/netlify-cms-lib-util/src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ export async function requestWithBackoff(
}
}

type HeaderObj = Record<string, string>

type HeaderConfig = {
headers?: HeaderObj,
token?: string
}
async function constructRequestHeaders(headerConfig: HeaderConfig) {
const { token, headers } = headerConfig
const baseHeaders: HeaderObj = {'Content-Type': 'application/json; charset=utf-8', ...headers}
if (token) {
baseHeaders['Authorization'] = `token ${token}`
}
return Promise.resolve(baseHeaders)
}
export async function readFile(
id: string | null | undefined,
fetchContent: () => Promise<string | Blob>,
Expand Down

0 comments on commit 3edc3ce

Please sign in to comment.