Skip to content

Commit

Permalink
feat(chromium): extra documentation and inclusion of header function …
Browse files Browse the repository at this point in the history
…in all fetch calls
  • Loading branch information
ecaroth committed Dec 6, 2024
1 parent 02166bd commit 0ba9d66
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,25 @@ Chromiumly.configure({
});
```

### Advanced Authentication / Headers

You can optionally pass in an async function to the client config to pass custom headers into the underlying `fetch` call to your Gotenberg instance.

This is useful for cases where you might need to do things like custom service account auth (if hosting on Google cloud run, for example), include custom proxy headers, ec.

Ex:

```typescript
Chromiumly.configure({
endpoint: "https://my-gotenberg-service-1234.us-central1.run.app",
addCustomHeadersFn: async () => ({
Authorization: `Bearer ${await generateIdToken()}`,
}),
});
```

_Note: if you include username/password the created `Authorization` heaer will overwrite any you supply from the custom headers function._

## Modules

Chromiumly introduces different classes that serve as wrappers to
Expand Down
3 changes: 2 additions & 1 deletion src/chromium/converters/html.converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ export class HtmlConverter extends Converter {
this.endpoint,
data,
Chromiumly.getGotenbergApiBasicAuthUsername(),
Chromiumly.getGotenbergApiBasicAuthPassword()
Chromiumly.getGotenbergApiBasicAuthPassword(),
await Chromiumly.getAddCustomHeadersFn()()
);
}
}
3 changes: 2 additions & 1 deletion src/chromium/screenshots/html.screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ export class HtmlScreenshot extends Screenshot {
this.endpoint,
data,
Chromiumly.getGotenbergApiBasicAuthUsername(),
Chromiumly.getGotenbergApiBasicAuthPassword()
Chromiumly.getGotenbergApiBasicAuthPassword(),
await Chromiumly.getAddCustomHeadersFn()()
);
}
}
3 changes: 2 additions & 1 deletion src/chromium/screenshots/markdown.screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export class MarkdownScreenshot extends Screenshot {
this.endpoint,
data,
Chromiumly.getGotenbergApiBasicAuthUsername(),
Chromiumly.getGotenbergApiBasicAuthPassword()
Chromiumly.getGotenbergApiBasicAuthPassword(),
await Chromiumly.getAddCustomHeadersFn()()
);
}
}
3 changes: 2 additions & 1 deletion src/chromium/screenshots/url.screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ export class UrlScreenshot extends Screenshot {
this.endpoint,
data,
Chromiumly.getGotenbergApiBasicAuthUsername(),
Chromiumly.getGotenbergApiBasicAuthPassword()
Chromiumly.getGotenbergApiBasicAuthPassword(),
await Chromiumly.getAddCustomHeadersFn()()
);
}
}
1 change: 1 addition & 0 deletions src/main.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export class Chromiumly {
* @param {string} config.endpoint - The Gotenberg service endpoint.
* @param {string} [config.username] - The username for basic authentication.
* @param {string} [config.password] - The password for basic authentication.
* @param {() => Promise<Record<string, string>>} [config.addCustomHeadersFn] - Optional async function to add custom headers to fetch
*/
public static configure(config: {
endpoint: string;
Expand Down

0 comments on commit 0ba9d66

Please sign in to comment.