-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
138 lines (120 loc) · 3.38 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
const express = require("express");
const app = express();
const ip = process.env.IP || "0.0.0.0";
const port = process.env.PORT || 8080;
const searchScholars4Dev = require("./scholars4Dev");
const searchScholars4DevPost = require("./scholars4DevPost");
const searchScholars4DevSitemap = require("./scholars4DevSitemap");
const searchScholars4DevCategory = require("./scholars4DevCategory");
const searchIndbeasiswa = require("./indbeasiswa");
const searchIndbeasiswaPost = require("./indbeasiswaPost");
const searchIndbeasiswaSitemap = require("./indbeasiswaSitemap");
const searchIndbeasiswaCategory = require("./indbeasiswaCategory");
app.get("/scholars4dev", (request, response) => {
const page = request.query.page;
if (page != null) {
searchScholars4Dev(page).then((results) => {
response.status(200);
response.json(results);
});
} else {
response.redirect("/scholars4dev?page=1");
}
});
app.get("/scholars4dev/post", (request, response) => {
const url = request.query.url;
if (url != null) {
searchScholars4DevPost(url).then((results) => {
response.status(200);
response.json(results);
});
} else {
response.end();
}
});
app.get("/scholars4dev/sitemap", (request, response) => {
let page = parseInt(request.query.page);
if (!page) {
page = 1;
}
searchScholars4DevSitemap().then((results) => {
const pageCount = Math.ceil(Object.keys(results).length / 10);
if (page > pageCount) {
response.status(400);
response.end();
} else {
response.status(200);
response.json({
page: page,
pageCount: pageCount,
posts: results.slice(page * 10 - 10, page * 10),
});
}
});
});
app.get("/scholars4dev/category", (request, response) => {
const url = request.query.url;
if (url != null) {
searchScholars4DevCategory(url).then((results) => {
response.status(200);
response.json(results);
});
} else {
response.end();
}
});
app.get("/indbeasiswa", (request, response) => {
const page = request.query.page;
if (page != null) {
searchIndbeasiswa(page).then((results) => {
response.status(200);
response.json(results);
});
} else {
response.redirect("/indbeasiswa?page=1");
}
});
app.get("/indbeasiswa/post", (request, response) => {
const url = request.query.url;
if (url != null) {
searchIndbeasiswaPost(url).then((results) => {
response.status(200);
response.json({ results, url });
});
} else {
response.end();
}
});
app.get("/indbeasiswa/sitemap", (request, response) => {
let page = parseInt(request.query.page);
if (!page) {
page = 1;
}
searchIndbeasiswaSitemap().then((results) => {
const pageCount = Math.ceil(Object.keys(results).length / 10);
if (page > pageCount) {
response.status(400);
response.end();
} else {
response.status(200);
response.json({
page: page,
pageCount: pageCount,
posts: results.slice(page * 10 - 10, page * 10),
});
}
});
});
app.get("/indbeasiswa/category", (request, response) => {
const url = request.query.url;
if (url != null) {
searchIndbeasiswaCategory(url).then((results) => {
response.status(200);
response.json(results);
});
} else {
response.end();
}
});
app.get("/", (req, res) => res.send("Scholarship Scraper by Wapp Lab"));
app.listen(port, ip);