-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathapp.js
49 lines (38 loc) · 1.56 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
const scapper = require('./scrapper')
const express = require('express')
const { env } = require('process')
const cors = require('cors')
const app = express()
app.use(cors())
app.get('/', (req, res) => {
res.send('👋 Hello world🌍, Welcome to 🦄 GogoAnime API 🧬 </br> Available routes : /Popular , /NewSeasons , /search/:query , /getAnime/:animeId , /getEpisode/:episodeId')
})
app.get('/Popular/:page', async (req, res) => {
const result = await scapper.popular(req.params.page)
res.header("Content-Type", 'application/json');
res.send(JSON.stringify(result, null, 4))
})
app.get('/NewSeasons/:page', async (req, res) => {
const result = await scapper.newSeason(req.params.page)
res.header("Content-Type", 'application/json');
res.send(JSON.stringify(result, null, 4))
})
app.get('/search/:query', async (req, res) => {
const result = await scapper.search(req.params.query)
res.header("Content-Type", 'application/json');
res.send(JSON.stringify(result, null, 4))
})
app.get('/getAnime/:query', async (req, res) => {
const result = await scapper.anime(req.params.query)
res.header("Content-Type", 'application/json');
res.send(JSON.stringify(result, null, 4))
})
app.get('/getEpisode/:query', async (req, res) => {
const result = await scapper.watchAnime(req.params.query)
res.header("Content-Type", 'application/json');
res.send(JSON.stringify(result, null, 4))
})
port = env.PORT || 3000
app.listen(port, () => {
console.log(`Listening to port ${port}`)
})