-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
58 lines (46 loc) · 1.41 KB
/
app.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
52
53
54
55
56
57
58
require("dotenv").config();
const express = require("express");
const { crawl } = require("./crawler");
const app = express();
const port = process.env.PORT || 5000;
// crawl("https://readmanganato.com/manga-ax951880", 101, 111, "manhua");
//allow cross-origin requests
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept"
);
if (req.method !== "OPTIONS") {
next();
} else {
res.sendStatus(200);
}
});
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.get("/", (req, res) => {
// serve the static html file
res.sendFile(__dirname + "/index.html");
});
app.post("/crawl_manga", (req, res) => {
if (!req.body) return res.sendStatus(400);
let { url, start, end, type } = req.body;
if (!url || start === null || end === null) return res.sendStatus(400);
if (!type) type = "manga";
crawl(url, start, end, type);
res.send("Crawling started");
res.end();
});
app.post("/test", (req, res) => {
if (!req.body) return res.sendStatus(400);
let { url, start, end, type } = req.body;
if (!url || start === null || end === null) return res.sendStatus(400);
if (!type) type = "manga";
console.log(url, start, end, type);
res.send("Crawling started");
res.end();
});
app.listen(port, () => {
console.log(`Manga Crawler Server listening on port ${port}\n`);
});