Skip to content

Commit

Permalink
added support for multiple tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
saifalfalah committed Apr 14, 2022
1 parent 43681f9 commit 3f50b09
Show file tree
Hide file tree
Showing 3 changed files with 525 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/http/post-index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ let data = require("@begin/data");
let parseBody = arc.http.helpers.bodyParser;
let axios = require("axios");
const { toDate, lightFormat } = require("date-fns");
const loadbalance = require("loadbalance");
const {
checkBodyUrl,
checkIsUrl,
Expand Down Expand Up @@ -77,12 +78,23 @@ exports.handler = async function http(req) {
// 5. Prepare api request url
const requestUrl = getApiRequestUrl(tweetPath);

const engine = loadbalance.random([
{ object: "a", weight: 7 },
{ object: "b", weight: 3 },
]);
const pick = engine.pick();

const authHeader =
pick === "a"
? `Bearer ${process.env.TOKEN}`
: `Bearer ${process.env.TOKEN2}`;

let data;
data = await axios({
method: "get",
url: requestUrl,
headers: {
authorization: `Bearer ${process.env.TOKEN}`,
authorization: authHeader,
},
});

Expand Down
Loading

0 comments on commit 3f50b09

Please sign in to comment.