Skip to content

Commit 3f50b09

Browse files
committed
added support for multiple tokens
1 parent 43681f9 commit 3f50b09

File tree

3 files changed

+525
-2
lines changed

3 files changed

+525
-2
lines changed

src/http/post-index/index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ let data = require("@begin/data");
33
let parseBody = arc.http.helpers.bodyParser;
44
let axios = require("axios");
55
const { toDate, lightFormat } = require("date-fns");
6+
const loadbalance = require("loadbalance");
67
const {
78
checkBodyUrl,
89
checkIsUrl,
@@ -77,12 +78,23 @@ exports.handler = async function http(req) {
7778
// 5. Prepare api request url
7879
const requestUrl = getApiRequestUrl(tweetPath);
7980

81+
const engine = loadbalance.random([
82+
{ object: "a", weight: 7 },
83+
{ object: "b", weight: 3 },
84+
]);
85+
const pick = engine.pick();
86+
87+
const authHeader =
88+
pick === "a"
89+
? `Bearer ${process.env.TOKEN}`
90+
: `Bearer ${process.env.TOKEN2}`;
91+
8092
let data;
8193
data = await axios({
8294
method: "get",
8395
url: requestUrl,
8496
headers: {
85-
authorization: `Bearer ${process.env.TOKEN}`,
97+
authorization: authHeader,
8698
},
8799
});
88100

0 commit comments

Comments
 (0)