-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
37 lines (30 loc) · 1.01 KB
/
server.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
const express = require("express");
const puppeteer = require("puppeteer");
const app = express();
let browser = undefined;
app.use(async (request, response, next) => {
if (browser === undefined) {
browser = await puppeteer.launch({ executablePath: "/usr/bin/chromium", args: ['--no-sandbox'], userDataDir: "/puppeteer-cache" });
}
next()
})
app.get("/", async (request, response) => {
const esfEncoded = request.query.fit;
if (esfEncoded === undefined || esfEncoded === "ENCODED_ESF_FIT") {
response.status(400);
response.send("Invalid request");
return;
}
const page = await browser.newPage();
await page.setViewport({
width: 1142,
height: 772,
});
await page.goto("https://eveship.fit/preview?fit=" + esfEncoded, { waitUntil: "networkidle0" });
image = await page.screenshot();
response.set("Content-Type", "image/png");
response.send(image);
});
app.listen(8080, () => {
console.log("Listening on port 8080...");
});