File tree Expand file tree Collapse file tree 3 files changed +525
-2
lines changed Expand file tree Collapse file tree 3 files changed +525
-2
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ let data = require("@begin/data");
3
3
let parseBody = arc . http . helpers . bodyParser ;
4
4
let axios = require ( "axios" ) ;
5
5
const { toDate, lightFormat } = require ( "date-fns" ) ;
6
+ const loadbalance = require ( "loadbalance" ) ;
6
7
const {
7
8
checkBodyUrl,
8
9
checkIsUrl,
@@ -77,12 +78,23 @@ exports.handler = async function http(req) {
77
78
// 5. Prepare api request url
78
79
const requestUrl = getApiRequestUrl ( tweetPath ) ;
79
80
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
+
80
92
let data ;
81
93
data = await axios ( {
82
94
method : "get" ,
83
95
url : requestUrl ,
84
96
headers : {
85
- authorization : `Bearer ${ process . env . TOKEN } ` ,
97
+ authorization : authHeader ,
86
98
} ,
87
99
} ) ;
88
100
You can’t perform that action at this time.
0 commit comments