Spaces:
jiome
/
Sleeping

cfoo commited on
Commit
655ca0f
·
verified ·
1 Parent(s): db97a8f

Create index.js

Browse files
Files changed (1) hide show
  1. index.js +44 -0
index.js ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Import the modules
2
+ const express = require('express');
3
+ const axios = require('axios');
4
+
5
+ // Create an express app
6
+ const app = express();
7
+
8
+ // Define a route for the root path
9
+ app.all('/', async (req, res) => {
10
+ // Initialize a counter for the loop
11
+ let count = 0;
12
+ // Initialize a flag for the success
13
+ let success = false;
14
+ // Loop until success or 10 times
15
+ while (!success && count < 10) {
16
+ try {
17
+ // Fetch the cookies from the given URL
18
+ let response = await axios.get('https://proxybing.nbing.eu.org/turing/captcha/challenge');
19
+ //let response = await axios.get('https://bing.cf03-b29.workers.dev/turing/captcha/challenge');
20
+ // Set the success flag to true
21
+ success = true;
22
+ // Get the cookies from the response header
23
+ let cookies = response.headers['set-cookie'];
24
+ // Remove all the "Path=/" from the cookies
25
+ cookies = cookies.map(cookie => cookie.replace('Path=/', ''));
26
+ // Join the cookies with semicolons
27
+ cookies = cookies.join('; ');
28
+ // Return the cookies as the body of the response
29
+ res.send(cookies); // 这里使用res.send方法,而不是res.json方法
30
+ } catch (error) {
31
+ // Increment the counter
32
+ count++;
33
+ }
34
+ }
35
+ // If the loop ends without success, return an error message
36
+ if (!success) {
37
+ res.status(500).send('Failed to get cookies');
38
+ }
39
+ });
40
+
41
+ // Run the express app, listen on port 7860
42
+ app.listen(7860, () => {
43
+ console.log('App is running on port 7860');
44
+ });