Update server.js
Browse files
server.js
CHANGED
|
@@ -3,26 +3,19 @@ const { chromium } = require("playwright");
|
|
| 3 |
|
| 4 |
const app = express();
|
| 5 |
|
| 6 |
-
app.get("
|
| 7 |
let browser;
|
| 8 |
try {
|
| 9 |
-
let { url } = req.
|
| 10 |
-
url
|
| 11 |
-
if (!url.trim().startsWith("http")) return res.sendStatus(400);
|
| 12 |
|
| 13 |
-
const { type, width, height } = req.query;
|
| 14 |
const viewports = {
|
| 15 |
-
desktop: { width:
|
| 16 |
-
mobile: { width:
|
| 17 |
-
tablet: { width:
|
| 18 |
};
|
| 19 |
|
| 20 |
-
let viewport;
|
| 21 |
-
if (width && height) {
|
| 22 |
-
viewport = { width: parseInt(width), height: parseInt(height) };
|
| 23 |
-
} else {
|
| 24 |
-
viewport = viewports[type] || viewports.desktop;
|
| 25 |
-
}
|
| 26 |
|
| 27 |
browser = await chromium.launch({
|
| 28 |
args: ["--incognito", "--single-process", "--no-sandbox", "--no-zygote", "--no-cache"],
|
|
|
|
| 3 |
|
| 4 |
const app = express();
|
| 5 |
|
| 6 |
+
app.get("/", async (req, res) => {
|
| 7 |
let browser;
|
| 8 |
try {
|
| 9 |
+
let { url, type, width, height } = req.query;
|
| 10 |
+
if (!url || !url.trim().startsWith("http")) return res.sendStatus(400);
|
|
|
|
| 11 |
|
|
|
|
| 12 |
const viewports = {
|
| 13 |
+
desktop: { width: 1920, height: 1080 },
|
| 14 |
+
mobile: { width: 1280, height: 720, isMobile: true },
|
| 15 |
+
tablet: { width: 1600, height: 900, isMobile: true },
|
| 16 |
};
|
| 17 |
|
| 18 |
+
let viewport = width && height ? { width: parseInt(width), height: parseInt(height) } : viewports[type] || viewports.desktop;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
browser = await chromium.launch({
|
| 21 |
args: ["--incognito", "--single-process", "--no-sandbox", "--no-zygote", "--no-cache"],
|