Update index.js
Browse files
index.js
CHANGED
@@ -1,46 +1,81 @@
|
|
1 |
-
// Import the modules
|
2 |
-
const express = require('express');
|
3 |
-
const axios = require('axios');
|
4 |
|
5 |
-
//
|
|
|
|
|
6 |
const app = express();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
//
|
9 |
-
app.all('/',
|
10 |
-
//
|
11 |
-
let
|
12 |
-
//
|
13 |
-
let
|
14 |
-
//
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
let response = await axios.get('https://getcaptcha.nbing.eu.org/turing/captcha/challenge');
|
19 |
-
//let response = await axios.get('https://proxybing.nbing.eu.org/turing/captcha/challenge');
|
20 |
-
//let response = await axios.get('https://bing.cf03-b29.workers.dev/turing/captcha/challenge');
|
21 |
-
// Set the success flag to true
|
22 |
-
success = true;
|
23 |
-
// Get the cookies from the response header
|
24 |
-
let cookies = response.headers['set-cookie'];
|
25 |
-
// Remove all the "Path=/" from the cookies
|
26 |
-
//cookies = cookies.map(cookie => cookie.replace('Path=/', ''));
|
27 |
-
// Join the cookies with semicolons
|
28 |
-
//cookies = cookies.join('; ');
|
29 |
-
cookies = cookies.map(cookie => cookie.split(';')[0]).join('; ');
|
30 |
-
// Return the cookies as the body of the response
|
31 |
-
res.send(cookies); // 这里使用res.send方法,而不是res.json方法
|
32 |
-
} catch (error) {
|
33 |
-
// Increment the counter
|
34 |
-
count++;
|
35 |
-
}
|
36 |
}
|
37 |
-
//
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
}
|
|
|
|
|
|
|
|
|
41 |
});
|
42 |
|
43 |
-
//
|
44 |
-
app.
|
45 |
-
|
|
|
46 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
|
2 |
+
// 引入 express 模块
|
3 |
+
const express = require('express');
|
4 |
+
// 创建 express 应用
|
5 |
const app = express();
|
6 |
+
// 定义全局字符串变量
|
7 |
+
let strValues = '';
|
8 |
+
// 设置端口号
|
9 |
+
const port = 7860;
|
10 |
+
// 从环境变量中获取密码
|
11 |
+
const password = process.env.PASSWORD || '123456' ;
|
12 |
+
|
13 |
+
// 处理 POST 请求
|
14 |
+
app.post('/SET', (req, res) => {
|
15 |
+
// 获取请求的方法
|
16 |
+
let method = req.method;
|
17 |
+
// 获取 pwd 参数的值
|
18 |
+
let pwd = req.query.pwd;
|
19 |
+
// 如果没有 pwd 参数,或者 pwd 参数的值不等于密码变量的值,返回错误信息
|
20 |
+
if (!pwd || pwd !== password) {
|
21 |
+
res.status(401).send('Invalid password');
|
22 |
+
return;
|
23 |
+
}
|
24 |
+
// 获取请求头中的 set-Values 值
|
25 |
+
let setValue = req.header('Cookie-Values');
|
26 |
+
// 如果有值,就存入全局变量
|
27 |
+
if (setValue) {
|
28 |
+
strValues = setValue;
|
29 |
+
// 返回成功信息
|
30 |
+
res.send('Set value successfully');
|
31 |
+
} else {
|
32 |
+
// 返回错误信息
|
33 |
+
res.status(400).send('No Cookie-Values in header');
|
34 |
+
}
|
35 |
+
});
|
36 |
|
37 |
+
// 处理 GET 请求
|
38 |
+
app.all('/GET', (req, res) => {
|
39 |
+
// 获取请求的方法
|
40 |
+
let method = req.method;
|
41 |
+
// 获取 pwd 参数的值
|
42 |
+
let pwd = req.query.pwd;
|
43 |
+
// 如果没有 pwd 参数,或者 pwd 参数的值不等于密码变量的值,返回错误信息
|
44 |
+
if (!pwd || pwd !== password) {
|
45 |
+
res.status(401).send('Invalid password');
|
46 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
}
|
48 |
+
// 将全局变量添加到 JSON 数据中
|
49 |
+
let result = { result: { cookies: strValues } };
|
50 |
+
// 返回 JSON 数据
|
51 |
+
res.json(result);
|
52 |
+
});
|
53 |
+
|
54 |
+
// 处理 CLS 请求
|
55 |
+
app.all('/CLS', (req, res) => {
|
56 |
+
// 获取请求的方法
|
57 |
+
let method = req.method;
|
58 |
+
// 获取 pwd 参数的值
|
59 |
+
let pwd = req.query.pwd;
|
60 |
+
// 如果没有 pwd 参数,或者 pwd 参数的值不等于密码变量的值,返回错误信息
|
61 |
+
if (!pwd || pwd !== password) {
|
62 |
+
res.status(401).send('Invalid password');
|
63 |
+
return;
|
64 |
}
|
65 |
+
// 清除全局变量的值
|
66 |
+
strValues = '';
|
67 |
+
// 返回成功信息
|
68 |
+
res.send('Clear value successfully');
|
69 |
});
|
70 |
|
71 |
+
// 处理 / 请求
|
72 |
+
app.all('/', (req, res) => {
|
73 |
+
// 返回提示信息
|
74 |
+
res.send('Please visit /SET /GET or /CLS with ?pwd=xxxxxx');
|
75 |
});
|
76 |
+
|
77 |
+
|
78 |
+
// 监听端口
|
79 |
+
app.listen(port, () => {
|
80 |
+
console.log(`Server is running on port ${port}`);
|
81 |
+
});
|