forked from eritislami/evobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
27 lines (25 loc) · 1010 Bytes
/
api.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
const firebase = require('./firebase')
module.exports = {
handleRequest(client, req, res) {
if (req.url == '/favicon.ico') {
return;
}
console.log(`${req.url} requested from: ${req.client.remoteAddress}`)
if (req.url == '/test') {
res.writeHead(200, {"Access-Control-Allow-Origin": "*"});
firebase.getAllSongHistory().then(result => {
res.end(JSON.stringify({result}, null, 2));
});
} else if (req.url == '/topsongs') {
res.writeHead(200, {"Access-Control-Allow-Origin": "*"});
firebase.getMostPlayedSongs(5).then(result => {
res.end(JSON.stringify(result, null, 2))
});
} else {
res.writeHead(200, {"Access-Control-Allow-Origin": "*"});
let songs = [];
client.queue.forEach(value => value.songs.forEach(song => songs.push(song)));
res.end(JSON.stringify({songs}, null, 2));
}
}
}