-
Notifications
You must be signed in to change notification settings - Fork 26
/
appserver.js
143 lines (114 loc) · 3.48 KB
/
appserver.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
var express = require('express');
var app = express();
var http=require('http');
app.all("*", function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization, Accept,X-Requested-With");
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
if (req.method == 'OPTIONS') {
res.send(200);
} else {
next();
}
});
function getIPAdress(){
var interfaces = require('os').networkInterfaces();
for(var devName in interfaces){
var iface = interfaces[devName];
for(var i=0;i<iface.length;i++){
var alias = iface[i];
if(alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal){
return alias.address;
}
}
}
}
app.get('/', function (req, res) {
var ip=getIPAdress()
res.send(ip)
})
app.get('/test', function (req, res) {
res.send('test')
})
app.get('/get', function (req, resn) {
var s=req.query.s?req.query.s:'许嵩';
s=encodeURI(s)
var size=req.query.size
var page=req.query.page
var html='';
var urle='http://api.open.itmf.cn/music/mf_music/search?app_id=dev_yunyi&key=KAHDIUWqlsdjswajlGEKAW32KJD92QccE3&s='+s+'&page='+page+'&size=40'
http.get(urle,function(res){
res.on('data',function(data){
html+=data;
});
res.on('end',function(){
var d=html.toString()
resn.send(JSON.parse(d))
// filechuli(html);
// console.log(JSON.parse(d));
});
})
})
app.get('/singerInfo', function (req, resn) {
var html='';
var name=req.query.name
name=encodeURI(name)
var urle='http://api.open.itmf.cn/music/mf_music/singer?name='+name+'&app_id=dev_yunyi&key=KAHDIUWqlsdjswajlGEKAW32KJD92QccE3'
http.get(urle,function(res){
res.on('data',function(data){
html+=data;
});
res.on('end',function(){
var d=html.toString()
resn.send(JSON.parse(d))
});
})
})
app.get('/song', function (req, resn) {//
var html='';
var hash=req.query.hash
hash=encodeURI(hash)
var urle='http://api.open.itmf.cn/music/mf_music/song?hash='+hash+'&app_id=dev_yunyi&key=KAHDIUWqlsdjswajlGEKAW32KJD92QccE3'
http.get(urle,function(res){
res.on('data',function(data){
html+=data;
});
res.on('end',function(){
var d=html.toString()
resn.send(JSON.parse(d))
});
})
})
app.get('/krc', function (req, resn) {//歌词
var html='';
var hash=req.query.hash
var name=req.query.name
var time=req.query.time
hash=encodeURI(hash)
name=encodeURI(name)
time=encodeURI(time)
var urle='http://api.open.itmf.cn/music/mf_music/krc?name='+name+'&time='+time+'&hash='+hash+'&app_id=dev_yunyi&key=KAHDIUWqlsdjswajlGEKAW32KJD92QccE3'
http.get(urle,function(res){
res.on('data',function(data){
html+=data;
});
res.on('end',function(){
var d=html.toString()
resn.send(JSON.parse(d))
});
})
})
var server = app.listen(8081, function () {
var adressip=getIPAdress()
var host = server.address().address;
var port = server.address().port;
console.log("本地ip为"+adressip+";若想手机端访问请打开home.vue的82行,localhost改为本地ip")
})
/*
http://api.open.itmf.cn/music/mf_music/[search/song/krc/singer]
?app_id=dev_yunyi
&key=KAHDIUWqlsdjswajlGEKAW32KJD92QccE3
&s=天下
&page=2
&size=20
*/