-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
38 lines (31 loc) · 974 Bytes
/
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
var path = require('path');
var express = require('express');
var pandora = require('./pandora');
var app = express();
app.configure(function() {
app.use(express.bodyParser());
app.use(express.static(path.join(__dirname, 'public')));
});
app.get('/station/:stationId/:startIndex', function(req, res) {
var stationId = req.params.stationId;
var startIndex = req.params.startIndex;
pandora.getSongs(stationId, startIndex, function(error, result) {
if (error)
res.json({ success: false });
else
res.json({ success: true, songs: result.songs, hasMore: result.hasMore });
});
});
app.get('/username/:username', function(req, res) {
var username = req.params.username;
pandora.getStations(username, function(error, stations) {
if (error)
res.json({ success: false });
else
res.json({ success: true, stations: stations });
});
});
var port = process.env.PORT || 8000;
app.listen(port, function() {
console.log('Listening on port ' + port);
});