-
Notifications
You must be signed in to change notification settings - Fork 71
/
server.js
67 lines (55 loc) · 1.79 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
const express = require('express')
const compression = require('compression')
const cors = require('cors')
const MusicApi = require('./index')
const port = process.env.PORT || 8001
const app = express()
// Enable CORS with various options
// https://github.com/expressjs/cors
app.use(cors())
// gzip
app.use(compression())
app.get('/api/search/song/:vendor', (req, res) => {
const { vendor } = req.params
MusicApi.searchSong(vendor, req.query || {})
.then(data => res.json(data))
.catch(err => res.send(err))
})
app.get('/api/search/album/:vendor', (req, res) => {
const { vendor } = req.params
MusicApi.searchAlbum(vendor, req.query || {})
.then(data => res.json(data))
.catch(err => res.send(err))
})
app.get('/api/search/playlist/:vendor', (req, res) => {
const { vendor } = req.params
MusicApi.searchPlaylist(vendor, req.query || {})
.then(data => res.json(data))
.catch(err => res.send(err))
})
app.get('/api/get/song/:vendor', (req, res) => {
const { vendor } = req.params
MusicApi.getSong(vendor, req.query || {})
.then(data => res.json(data))
.catch(err => res.send(err))
})
app.get('/api/get/album/:vendor', (req, res) => {
const { vendor } = req.params
MusicApi.getAlbum(vendor, req.query || {})
.then(data => res.json(data))
.catch(err => res.send(err))
})
app.get('/api/get/playlist/:vendor', (req, res) => {
const { vendor } = req.params
MusicApi.getPlaylist(vendor, req.query || {})
.then(data => res.json(data))
.catch(err => res.send(err))
})
app.get('/api/suggest/album/:vendor', (req, res) => {
const { vendor } = req.params
MusicApi.getSuggestAlbums(vendor, req.query || {})
.then(data => res.json(data))
.catch(err => res.send(err))
})
app.listen(port)
console.log(`server started on port ${port}`) // eslint-disable-line