forked from hua1995116/musiccloudWebapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prod.server.js
58 lines (51 loc) · 1.14 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
var express = require('express');
var config = require('./config/index');
var api = require('musicapi');
var port = process.env.PORT || config.dev.port;
var app = express();
var router = express.Router();
router.get('/',function(req,res,next){
req.url = './index.html';
next();
});
app.use(router);
app.get('/key/:key', function (req, res) {
var seller = {
name: req.params.key
};
var Res = res;
api.search(req.params.key, function (err, res, body) {
if (err) console.error(err);
if (res.statusCode === 200) {
Res.json({
error: 0,
data: body,
code: 200
});
}
});
});
app.get('/detail/:key', function (req, res) {
var seller = {
name: req.params.key
};
var Res = res;
api.id(req.params.key, 'song', function (err, res, body) {
if (err) console.error(err);
if (res.statusCode === 200) {
Res.json({
error: 0,
data: body,
code: 200
});
}
});
});
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')
});