Merge pull request #2920 from balena-io/x-balena-client-fix

Fix CORS issue with X-Balena-Client header
This commit is contained in:
flowzone-app[bot] 2025-02-26 12:51:20 +00:00 committed by GitHub
commit 9f097a96f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -46,9 +46,13 @@ export const onceAsync = <T>(fn: () => Promise<T>) => {
const cliXBalenaClientHeaderInterceptor: BalenaSdk.Interceptor = {
request($request) {
// We intentionally overwrite the sdk version string from the header
// to conserve bandwidth.
$request.headers['X-Balena-Client'] = `balena-cli/${version}`;
if ($request.headers['X-Balena-Client']) {
// We intentionally overwrite the sdk version string from the header
// to conserve bandwidth. We only do that when the SDK already has specified
// the X-Balena-Client header, since that signals that this is a safe url to
// include the extra header and will not cause CORS errors.
$request.headers['X-Balena-Client'] = `balena-cli/${version}`;
}
return $request;
},
};