-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathserver.js
87 lines (71 loc) · 2 KB
/
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
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
// SERVER-SIDE JAVASCRIPT
//require express in our app
var express = require('express');
// generate a new express app and call it 'app'
var app = express();
// serve static files from public folder
app.use(express.static(__dirname + '/public'));
/************
* DATABASE *
************/
/* hard-coded data */
var albums = [];
albums.push({
_id: 132,
artistName: 'the Old Kanye',
name: 'The College Dropout',
releaseDate: '2004, February 10',
genres: [ 'rap', 'hip hop' ]
});
albums.push({
_id: 133,
artistName: 'the New Kanye',
name: 'The Life of Pablo',
releaseDate: '2016, Febraury 14',
genres: [ 'hip hop' ]
});
albums.push({
_id: 134,
artistName: 'the always rude Kanye',
name: 'My Beautiful Dark Twisted Fantasy',
releaseDate: '2010, November 22',
genres: [ 'rap', 'hip hop' ]
});
albums.push({
_id: 135,
artistName: 'the sweet Kanye',
name: '808s & Heartbreak',
releaseDate: '2008, November 24',
genres: [ 'r&b', 'electropop', 'synthpop' ]
});
/**********
* ROUTES *
**********/
/*
* HTML Endpoints
*/
app.get('/', function homepage (req, res) {
res.sendFile(__dirname + '/views/index.html');
});
/*
* JSON API Endpoints
*/
app.get('/api', function api_index (req, res){
res.json({
message: "Welcome to tunely!",
documentation_url: "https://github.com/tgaff/tunely/api.md",
base_url: "http://tunely.herokuapp.com",
endpoints: [
{method: "GET", path: "/api", description: "Describes available endpoints"}
]
});
});
app.get('/api/albums', function album_index(req, res){
})
/**********
* SERVER *
**********/
// listen on port 3000
app.listen(process.env.PORT || 3000, function () {
console.log('Express server is running on http://localhost:3000/');
});