-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathserver.js
More file actions
37 lines (32 loc) · 1.13 KB
/
server.js
File metadata and controls
37 lines (32 loc) · 1.13 KB
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
var express = require('express');
var app = express();
var request = require('request');
app.set('port', (process.env.PORT || 5000));
app.use(express.static('./public'));
app.get('/', function(req, res) {
res.sendfile('./public/index.html');
});
app.get('/storytime', function(req, res) {
res.send("<p> Hey " + req.query.name + " nice to meet you! I think like to "+ req.query.verb +
" this has been an awesome story of "+ req.query.adjective + " , you're totally welcome </p>");
});
app.get('/music', function(req, res){
request('https://api.spotify.com/v1/search?q=Muse&type=album', function (error, response, body) {
if (!error && response.statusCode == 200) {
var elements = ['<!doctype html5><html>'];
body.albums.items.forEach(function(album) {
try {
elements.push('<a href="' + album.href + '"><img src="' + album.images[0].url + '"></a>');
} catch (err) {
console.log(err);
res.status(200).send(err);
}
});
elements.push('</html>');
res.status(200).send(elements.join(''));
}
});
});
app.listen(app.get('port'), function() {
console.log('Fuck it ship it.');
});