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 1 commit
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` | Authorization header value like this: `Bearer *****` |
doriaviram marked this conversation as resolved.
Show resolved Hide resolved

> [!IMPORTANT]
> Be sure to post only to a trusted server.
Expand Down
13 changes: 10 additions & 3 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 @@ -25,12 +26,18 @@ export class WebPostStorage implements TransactionStorage {

logger(`Posting ${nonPendingTxns.length} transactions to ${this.url}`);

const headers = {
"Content-Type": "application/json",
};

if(!!this.authorizationToken) {
headers["Authorization"] = this.authorizationToken;
}

doriaviram marked this conversation as resolved.
Show resolved Hide resolved
const [response] = await Promise.all([
fetch(this.url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
headers: headers,
doriaviram marked this conversation as resolved.
Show resolved Hide resolved
body: JSON.stringify(nonPendingTxns.map((tx) => tableRow(tx))),
}),
onProgress("Sending"),
Expand Down
Loading