-
Notifications
You must be signed in to change notification settings - Fork 2
/
api.js
140 lines (124 loc) · 3.47 KB
/
api.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
139
140
import express from 'express';
import cors from 'cors';
import { scrapeLatestManga,
scrapeTopManga,
scrapeNewManga,
scrapeSearch,
scrapeTopCompletedManga,
scrapeMangaDetails,
scrapeGenreManga
} from './manga_parser.js';
const port = process.env.PORT || 3000;
const corsOptions = {
origin: '*',
credentials: true,
optionSuccessStatus: 200,
port: port,
};
const app = express();
app.use(cors(corsOptions));
app.use(express.json());
app.get('/', (req, res) => {
res.status(200).json('Welcome to the Manga API made by MrCain!');
});
app.get('/latest-manga', async (req, res) => {
try {
const page = req.query.page;
const data = await scrapeLatestManga({ page: page });
res.status(200).json(data);
} catch (err) {
res.status(500).json({
status: 500,
error: 'Internal Error',
message: err.message, // Change this to err.message to provide better error information
});
}
});
app.get('/top-manga', async (req, res) => {
try {
const page = req.query.page;
const data = await scrapeTopManga({ page: page });
res.status(200).json(data);
} catch (err) {
res.status(500).json({
status: 500,
error: 'Internal Error',
message: err.message, // Change this to err.message to provide better error information
});
}
});
app.get('/new-manga', async (req, res) => {
try {
const page = req.query.page;
const data = await scrapeNewManga({ page: page });
res.status(200).json(data);
} catch (err) {
res.status(500).json({
status: 500,
error: 'Internal Error',
message: err.message, // Change this to err.message to provide better error information
});
}
});
app.get('/search', async(req, res) => {
try {
const keyw = req.query.keyw;
const page = req.query.page;
const data = await scrapeSearch({ keyw: keyw, page: page });
res.status(200).json(data);
} catch (err) {
res.status(500).json({
status: 500,
error: 'Internal Error',
message: err,
});
}
});
app.get('/top-completed-manga', async (req, res) => {
try {
const page = req.query.page;
const data = await scrapeTopCompletedManga({ page: page });
res.status(200).json(data);
} catch (err) {
res.status(500).json({
status: 500,
error: 'Internal Error',
message: err.message, // Change this to err.message to provide better error information
});
}
});
app.get('/genre-list-manga', async (req, res) => {
try {
const page = req.query.page;
const data = await scrapeGenreManga({ page: page });
res.status(200).json(data);
} catch (err) {
res.status(500).json({
status: 500,
error: 'Internal Error',
message: err.message, // Change this to err.message to provide better error information
});
}
});
app.get('/manga-details/:id', async(req, res) => {
try {
const id = req.params.id;
const data = await scrapeMangaDetails({ id: id });
res.status(200).json(data);
} catch (err) {
res.status(500).json({
status: 500,
error: 'Internal Error',
message: err,
});
}
});
app.use((req, res) => {
res.status(404).json({
status: 404,
error: 'Not Found',
});
});
app.listen(port, () => {
console.log(`Express server listening on port ${port}`);
});