-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprod.server.js
123 lines (114 loc) · 3.51 KB
/
prod.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
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
/* 起服务:将打包后的代码运行在服务之上 */
let express = require('express')
// var config = require('./config/index')
let axios = require('axios')
let bodyParser = require('body-parser')
/* process是全局变量无需引入 */
let port = 80
let app = express()
let apiRoutes = express.Router()
/* 用来解析req.body的数据 解析成功覆盖原来的req.body,解析失败则为{} */
/* extend选项用来配置使用querystring(false)或qs(true)来解析数据*/
/* qs比querystring出色的地方在于可以解析多级嵌套的复杂对象(最多5级) */
apiRoutes.use(bodyParser.urlencoded({extended:true}))
/* 歌单 */
apiRoutes.get('/api/getDisList', function (req, res) {
let url = 'https://c.y.qq.com/splcloud/fcgi-bin/fcg_get_diss_by_tag.fcg'
axios.get(url, {
headers: {
referer: 'https://c.y.qq.com/',
host: 'c.y.qq.com'
},
params: req.query
}).then((response) => {
res.json(response.data)
}).catch((e) => {
console.log(e)
})
})
/* 歌曲url */
apiRoutes.post('/api/getPurlUrl',bodyParser.json(),function (req,res) {
const url = 'http://u.y.qq.com/cgi-bin/musicu.fcg'
axios.post(url,req.body,{
headers:{
referer:'https://y.qq.com',
origin:'https://y.qq.com',
'Content-type':'application/x-www-form-urlencoded'
}
}).then((response) => {
res.json(response.data)
}).catch((e)=>{
console.log(e);
})
})
// 获取歌单详情
apiRoutes.get('/api/getDisc', (req, res) => {
const url = 'https://c.y.qq.com/qzone/fcg-bin/fcg_ucc_getcdinfo_byids_cp.fcg'
axios.get(url, {
headers: {
referer: 'https://y.qq.com/n/yqq/playsquare/4291589977.html',
origin: 'https://y.qq.com'
},
params: req.query
}).then((response) => {
res.json(response.data)
}).catch((e) => {
console.log(e)
})
})
// 获取歌曲信息
apiRoutes.post('/api/getPurlUrl', bodyParser.json(), function (req, res) {
const url = 'https://u.y.qq.com/cgi-bin/musicu.fcg'
axios.post(url, req.body, {
headers: {
referer: 'https://y.qq.com/',
origin: 'https://y.qq.com',
'Content-type': 'application/x-www-form-urlencoded'
}
}).then((response) => {
res.json(response.data)
}).catch((e) => {
console.log(e)
})
})
// 获取歌词信息
apiRoutes.get('/api/lyric', (req, res) => {
let url = 'https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg'
axios.get(url, {
headers: {
referer: 'https://c.y.qq.com/',
host: 'c.y.qq.com'
},
params: req.query
}).then((response) => {
res.json(response.data)
}).catch((e) => {
console.log(e)
})
})
// 搜索
apiRoutes.get('/api/searchFor', (req, res) => {
let url = 'https://c.y.qq.com/soso/fcgi-bin/search_for_qq_cp'
axios.get(url, {
headers: {
referer: 'https://y.qq.com/m/index.html',
origin: 'https://y.qq.com'
},
params: req.query
}).then((response) => {
res.json(response.data)
}).catch((e) => {
console.log(e)
})
})
app.use('/',apiRoutes)
/* Express框架:提供了static中间件来设置静态文件的资源 */
app.use(express.static('./dist'))
/* 起端口 */
module.exports = app.listen(port, function (err) {
if(err){
console.log(err);
return
}
console.log('Listening at http://localhost:' + port + '\n');
})