Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding authorization header to web-post #371

Merged
merged 5 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,10 @@ The transactions will be sent as a JSON array in the body of the request with th

Use the following env vars to setup:

| env variable name | description |
| ----------------- | ------------------ |
| `WEB_POST_URL ` | The URL to post to |
| env variable name | description |
| ------------------------------ | ---------------------------------------------------------------------------- |
| `WEB_POST_URL` | The URL to post to |
| `WEB_POST_AUTHORIZATION_TOKEN` | The Authorization header value (i.e. `Bearer *****`, but can use any schema) |

> [!IMPORTANT]
> Be sure to post only to a trusted server.
Expand Down
4 changes: 4 additions & 0 deletions src/bot/storage/web-post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const logger = createLogger("WebPostStorage");

export class WebPostStorage implements TransactionStorage {
private url = process.env.WEB_POST_URL || "";
private authorizationToken = process.env.WEB_POST_AUTHORIZATION_TOKEN || "";

canSave() {
return Boolean(this.url) && URL.canParse(this.url);
Expand All @@ -30,6 +31,9 @@ export class WebPostStorage implements TransactionStorage {
method: "POST",
headers: {
"Content-Type": "application/json",
...(this.authorizationToken && {
Authorization: this.authorizationToken,
}),
},
body: JSON.stringify(nonPendingTxns.map((tx) => tableRow(tx))),
}),
Expand Down