Skip to content

Commit 79b7da8

Browse files
feat: support setting headers via env
1 parent 21fe6ee commit 79b7da8

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/client.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,18 @@ export class ImageKit {
260260
this.fetch = options.fetch ?? Shims.getDefaultFetch();
261261
this.#encoder = Opts.FallbackEncoder;
262262

263+
const customHeadersEnv = readEnv('IMAGE_KIT_CUSTOM_HEADERS');
264+
if (customHeadersEnv) {
265+
const parsed: Record<string, string> = {};
266+
for (const line of customHeadersEnv.split('\n')) {
267+
const colon = line.indexOf(':');
268+
if (colon >= 0) {
269+
parsed[line.substring(0, colon).trim()] = line.substring(colon + 1).trim();
270+
}
271+
}
272+
options.defaultHeaders = { ...parsed, ...options.defaultHeaders };
273+
}
274+
263275
this._options = options;
264276

265277
this.privateKey = privateKey;

0 commit comments

Comments
 (0)