Update server.js
Browse files
server.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
| 1 |
const express = require("express");
|
| 2 |
const { chromium } = require("playwright");
|
| 3 |
-
const bodyParser = require("body-parser");
|
| 4 |
|
| 5 |
const app = express();
|
| 6 |
-
app.use(
|
| 7 |
|
| 8 |
app.post("/v1/start", async (req, res) => {
|
| 9 |
try {
|
| 10 |
-
const html = req.body;
|
| 11 |
-
if (!html) return res.sendStatus(400);
|
| 12 |
|
| 13 |
const browser = await chromium.launch({ args: ["--no-sandbox"] });
|
| 14 |
const page = await browser.newPage();
|
|
@@ -20,9 +19,10 @@ app.post("/v1/start", async (req, res) => {
|
|
| 20 |
|
| 21 |
res.setHeader("Content-Type", "image/png");
|
| 22 |
res.send(buffer);
|
| 23 |
-
} catch {
|
|
|
|
| 24 |
res.sendStatus(500);
|
| 25 |
}
|
| 26 |
});
|
| 27 |
|
| 28 |
-
app.listen(7860);
|
|
|
|
| 1 |
const express = require("express");
|
| 2 |
const { chromium } = require("playwright");
|
|
|
|
| 3 |
|
| 4 |
const app = express();
|
| 5 |
+
app.use(express.raw({ type: "text/html", limit: "1mb" }));
|
| 6 |
|
| 7 |
app.post("/v1/start", async (req, res) => {
|
| 8 |
try {
|
| 9 |
+
const html = req.body.toString();
|
| 10 |
+
if (!html.trim()) return res.sendStatus(400);
|
| 11 |
|
| 12 |
const browser = await chromium.launch({ args: ["--no-sandbox"] });
|
| 13 |
const page = await browser.newPage();
|
|
|
|
| 19 |
|
| 20 |
res.setHeader("Content-Type", "image/png");
|
| 21 |
res.send(buffer);
|
| 22 |
+
} catch (err) {
|
| 23 |
+
console.error(err);
|
| 24 |
res.sendStatus(500);
|
| 25 |
}
|
| 26 |
});
|
| 27 |
|
| 28 |
+
app.listen(7860, () => console.log("Running on port 7860"));
|