-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue.config.js
165 lines (156 loc) · 5.27 KB
/
vue.config.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
const path = require('path')
const bodyParser = require('body-parser')
const axios = require('axios')
function resolve (dir) {
return path.join(__dirname, dir)
}
module.exports = {
devServer: {
before (app) {
/* 获取推荐页面歌单列表数据 */
app.get('/api/getDiscList', function (req, res) {
const url = 'https://c.y.qq.com/splcloud/fcgi-bin/fcg_get_diss_by_tag.fcg'
// 通过axios向目标服务器发送HTTP请求,获取歌单数据
axios.get(url, {
headers: {
referer: 'https://c.y.qq.com/',
host: 'c.y.qq.com'
},
params: req.query
}).then((response) => {
// response是从目标服务器返回的带有HTTP响应头部数据和实际请求的歌单数据的一个对象
/* response.data是实际请求的歌单数据的一个对象,调用res.json()是将response.data转化成JSON数据格式,并作为
res返回。res是要返回给浏览器的响应数据,是一个带有HTTP响应头部数据和实际请求的歌单数据的对象 */
res.json(response.data)
}).catch((e) => {
console.log(e)
})
})
app.get('/api/getDiscDetail', function (req, res) {
const url = 'https://c.y.qq.com/qzone/fcg-bin/fcg_ucc_getcdinfo_byids_cp.fcg'
axios.get(url, {
headers: {
referer: 'https://c.y.qq.com/',
host: 'c.y.qq.com'
},
params: req.query
}).then((response) => {
let ret = response.data
if (typeof ret === 'string') {
const reg = /^\w+\(({.+})\)$/
const matches = ret.match(reg)
if (matches) {
ret = JSON.parse(matches[1])
}
}
res.json(ret)
}).catch((e) => {
console.log(e)
})
})
/* 获取歌手详情页面歌曲的歌词数据 */
app.get('/api/lyric', function (req, res) {
const 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) => {
let ret = response.data
/* 如果ret是一个JSONP形式的数据,即一个回调函数包裹实际
数据的字符串,则从中提取出有效数据,并解析成对象 */
if (typeof ret === 'string') {
const reg = /^\w+\(({.+})\)$/
const matches = ret.match(reg)
if (matches) {
ret = JSON.parse(matches[1])
}
}
res.json(ret)
}).catch((e) => {
console.log(e)
})
})
app.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)
})
})
app.get('/api/search', function (req, res) {
const url = 'https://c.y.qq.com/soso/fcgi-bin/search_for_qq_cp'
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)
})
})
app.get('/api/getTopBanner', function (req, res) {
const url = 'https://u.y.qq.com/cgi-bin/musicu.fcg'
const jumpPrefixMap = {
10002: 'https://y.qq.com/n/yqq/album/',
10014: 'https://y.qq.com/n/yqq/playlist/',
10012: 'https://y.qq.com/n/yqq/mv/v/'
}
axios.get(url, {
headers: {
referer: 'https://u.y.qq.com/',
host: 'u.y.qq.com'
},
params: req.query
}).then((response) => {
response = response.data
if (response.code === 0) {
const slider = []
const content = response.focus.data && response.focus.data.content
if (content) {
for (let i = 0; i < content.length; i++) {
const item = content[i]
const sliderItem = {}
const jumpPrefix = jumpPrefixMap[item.type || 10002]
sliderItem.id = item.id
sliderItem.linkUrl = jumpPrefix + item.jump_info.url + '.html'
sliderItem.picUrl = item.pic_info.url
slider.push(sliderItem)
}
}
res.json({
code: 0,
data: {
slider
}
})
} else {
res.json(response)
}
}).catch((e) => {
console.log(e)
})
})
}
},
chainWebpack (config) {
config.resolve.alias
.set('components', resolve('src/components'))
.set('common', resolve('src/common'))
.set('api', resolve('src/api'))
.set('base', resolve('src/base'))
},
publicPath: ''
}