forked from amamenko/puppeteer-render
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (43 loc) · 1.23 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const express = require("express");
const { scrapeLogic, checker,captureScreenshot } = require("./scrapeLogic");
const app = express();
const PORT = process.env.PORT || 4000;
// Add the body parsing middleware here
app.use(express.json());
app.get("/scrape", (req, res) => {
scrapeLogic(res);
});
app.post("/check", async (req, res) => {
const { email, password } = req.body;
try {
const result = await checker(email, password);
res.json({ result });
} catch (error) {
console.error(error);
res.status(500).json({ error: 'An error occurred while checking credentials.' });
}
});
app.post("/capture", async (req, res) => {
const { url } = req.body;
try {
const screenshotData = await captureScreenshot(url);
const htmlResponse = `
<html>
<body>
<h1>Screenshot</h1>
<img src="data:image/png;base64,${screenshotData}" />
</body>
</html>
`;
res.send(htmlResponse);
} catch (error) {
console.error(error);
res.status(500).json({ error: 'An error occurred while capturing the screenshot.' });
}
});
app.get("/", (req, res) => {
res.send("Render Puppeteer server is up and running!");
});
app.listen(PORT, () => {
console.log(`Listening on port ${PORT}`);
});