forked from theriturajps/Torrent-Search-API
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
46 lines (37 loc) · 1.23 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
const express = require('express');
const combo = require("./torrent/COMBO")
const path = require('path');
let torrents = require("./torrent/torrents")()
const app = express();
app.use(express.static(path.join(__dirname, 'public')));
app.use('/api/:website/:query/:page?', (req, res, next) => {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
let website = (req.params.website).toLowerCase();
let query = req.params.query;
let page = req.params.page;
if (website == "all") {
combo(query, page).then(v => {
console.log(v)
res.json(v)
})
} else if (torrents[website]) {
torrents[website](query, page).then((v) => {
console.log(v)
res.json(v)
})
} else {
res.json({
error: `Please select "${Object.keys(torrents).join(" | ")}"`
})
}
});
app.get("/api/torrents", (req, res) => {
res.json(Object.keys(torrents))
})
app.use('/', (req, res) => {
res.sendFile(path.join(__dirname, 'public', 'index.html'));
});
const PORT = process.env.PORT || 3001;
console.log('Listening on PORT : ', PORT);
app.listen(PORT);