-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
72 lines (57 loc) · 1.7 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import express from "express";
import cors from "cors";
///local import
import { port } from "./settings.js";
import {
routeAnimeDetail,
routeAnimeFinished,
routeAnimeList,
routeAnimeOngoing,
routeAnimeSearch,
routeAnimeStream,
} from "./route.js";
//initialize the express
const app = express();
//cors
app.use(cors());
app.use((req, res, next) => {
const token = req.headers.authorization;
next();
// if (token && isValidToken(token)) {
// next();
// } else {
// res.status(401).json({ message: "You are not Authorized" });
// }
});
function isValidToken(token) {
if (token == "Bearer Kurodoke") return true;
return false;
}
//routes
app.all("/", function (req, res) {
res.send(
"<h1>welcome to anime REST API</h1> <h3>add the /api/ to the url to access the api</h3> <p>read the documentation of the api for the detail</p>"
);
});
app.get("/api/headers", async function (req, res) {
try {
let html = await axios.get("http://httpbin.org/headers", headerOPT);
res.send(html);
} catch {}
});
//route search
app.get("/api/search/:searchName/:page?/:orderBy?", routeAnimeSearch);
//route anime detail
app.get("/api/anime/:animeId/:animeSlug/:page?", routeAnimeDetail);
//route anime finished
app.get("/api/finished/:page?/:orderBy?", routeAnimeFinished);
//route anime ongoing
app.get("/api/ongoing/:page?/:orderBy?", routeAnimeOngoing);
//route anime list
app.get("/api/animelist/:page?/:orderBy?", routeAnimeList);
//route anime episode(stream)
app.get("/api/anime/:animeId/:animeSlug/episode/:episodeNum", routeAnimeStream);
//start server
app.listen(port, () => {
console.log(`listening on port ${port}`);
});