Upload 6 files
Browse files- .gitignore +1 -0
- Dockerfile +15 -0
- package-lock.json +0 -0
- package.json +20 -0
- server.js +56 -0
- test.js +52 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
node_modules
|
Dockerfile
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM node:latest
|
2 |
+
|
3 |
+
# Create app directory
|
4 |
+
WORKDIR /usr/src/app
|
5 |
+
|
6 |
+
# Install app dependencies
|
7 |
+
COPY package*.json ./
|
8 |
+
RUN npm install
|
9 |
+
|
10 |
+
# Bundle app source
|
11 |
+
COPY . .
|
12 |
+
|
13 |
+
# Expose port and start application
|
14 |
+
EXPOSE 8080
|
15 |
+
CMD [ "node", "server.js" ]
|
package-lock.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
package.json
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"dependencies": {
|
3 |
+
"chrome-aws-lambda": "^10.1.0",
|
4 |
+
"cors": "^2.8.5",
|
5 |
+
"express": "^4.18.2",
|
6 |
+
"puppeteer": "^21.1.0",
|
7 |
+
"puppeteer-core": "^21.1.0"
|
8 |
+
},
|
9 |
+
"name": "server",
|
10 |
+
"version": "1.0.0",
|
11 |
+
"main": "index.js",
|
12 |
+
"scripts": {
|
13 |
+
"start": "node server.js",
|
14 |
+
"test": "echo \"Error: no test specified\" && exit 1"
|
15 |
+
},
|
16 |
+
"keywords": [],
|
17 |
+
"author": "",
|
18 |
+
"license": "ISC",
|
19 |
+
"description": ""
|
20 |
+
}
|
server.js
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const app = require("express")();
|
2 |
+
|
3 |
+
let chrome = {};
|
4 |
+
let puppeteer;
|
5 |
+
|
6 |
+
if (process.env.AWS_LAMBDA_FUNCTION_VERSION) {
|
7 |
+
chrome = require("chrome-aws-lambda");
|
8 |
+
puppeteer = require("puppeteer-core");
|
9 |
+
} else {
|
10 |
+
puppeteer = require("puppeteer");
|
11 |
+
}
|
12 |
+
|
13 |
+
app.get("/", (req, res) => {
|
14 |
+
res.send('Hello AuthCode')
|
15 |
+
})
|
16 |
+
|
17 |
+
app.get("/api", async (req, res) => {
|
18 |
+
let options = {};
|
19 |
+
|
20 |
+
if (process.env.AWS_LAMBDA_FUNCTION_VERSION) {
|
21 |
+
options = {
|
22 |
+
args: [...chrome.args, "--hide-scrollbars", "--disable-web-security"],
|
23 |
+
defaultViewport: chrome.defaultViewport,
|
24 |
+
executablePath: await chrome.executablePath,
|
25 |
+
headless: true,
|
26 |
+
ignoreHTTPSErrors: true,
|
27 |
+
};
|
28 |
+
}
|
29 |
+
|
30 |
+
try {
|
31 |
+
let browser = await puppeteer.launch(options);
|
32 |
+
|
33 |
+
let page = await browser.newPage();
|
34 |
+
await page.goto("https://liaobots.work/");
|
35 |
+
await page.click('label.button');
|
36 |
+
await page.waitForNavigation();
|
37 |
+
await page.waitForTimeout(2000);
|
38 |
+
|
39 |
+
// Execute JavaScript code in the context of the page
|
40 |
+
const value = await page.evaluate(() => {
|
41 |
+
// Retrieve the value from localStorage
|
42 |
+
return localStorage.getItem('authCode');
|
43 |
+
});
|
44 |
+
|
45 |
+
res.send(value);
|
46 |
+
} catch (err) {
|
47 |
+
console.error(err);
|
48 |
+
return null;
|
49 |
+
}
|
50 |
+
});
|
51 |
+
|
52 |
+
app.listen(process.env.PORT || 3000, () => {
|
53 |
+
console.log("Server started");
|
54 |
+
});
|
55 |
+
|
56 |
+
module.exports = app;
|
test.js
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const app = require("express")();
|
2 |
+
|
3 |
+
let chrome = {};
|
4 |
+
let puppeteer;
|
5 |
+
|
6 |
+
if (process.env.AWS_LAMBDA_FUNCTION_VERSION) {
|
7 |
+
chrome = require("chrome-aws-lambda");
|
8 |
+
puppeteer = require("puppeteer-core");
|
9 |
+
} else {
|
10 |
+
puppeteer = require("puppeteer");
|
11 |
+
}
|
12 |
+
|
13 |
+
app.get("/api", async (req, res) => {
|
14 |
+
let options = {};
|
15 |
+
|
16 |
+
if (process.env.AWS_LAMBDA_FUNCTION_VERSION) {
|
17 |
+
options = {
|
18 |
+
args: [...chrome.args, "--hide-scrollbars", "--disable-web-security"],
|
19 |
+
defaultViewport: chrome.defaultViewport,
|
20 |
+
executablePath: await chrome.executablePath,
|
21 |
+
headless: true,
|
22 |
+
ignoreHTTPSErrors: true,
|
23 |
+
};
|
24 |
+
}
|
25 |
+
|
26 |
+
try {
|
27 |
+
let browser = await puppeteer.launch(options);
|
28 |
+
|
29 |
+
let page = await browser.newPage();
|
30 |
+
await page.goto("https://liaobots.work/");
|
31 |
+
await page.click('label.button');
|
32 |
+
await page.waitForNavigation();
|
33 |
+
await page.waitForTimeout(2000);
|
34 |
+
|
35 |
+
// Execute JavaScript code in the context of the page
|
36 |
+
const value = await page.evaluate(() => {
|
37 |
+
// Retrieve the value from localStorage
|
38 |
+
return localStorage.getItem('authCode');
|
39 |
+
});
|
40 |
+
|
41 |
+
res.send(value);
|
42 |
+
} catch (err) {
|
43 |
+
console.error(err);
|
44 |
+
return null;
|
45 |
+
}
|
46 |
+
});
|
47 |
+
|
48 |
+
app.listen(process.env.PORT || 3000, () => {
|
49 |
+
console.log("Server started");
|
50 |
+
});
|
51 |
+
|
52 |
+
module.exports = app;
|