forked from tgaff/tunely
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathserver.js
83 lines (69 loc) · 1.94 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
// 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: 'Nine Inch Nails',
name: 'The Downward Spiral',
releaseDate: '1994, March 8',
genres: [ 'industrial', 'industrial metal' ]
});
albums.push({
_id: 133,
artistName: 'Metallica',
name: 'Metallica',
releaseDate: '1991, August 12',
genres: [ 'heavy metal' ]
});
albums.push({
_id: 134,
artistName: 'The Prodigy',
name: 'Music for the Jilted Generation',
releaseDate: '1994, July 4',
genres: [ 'electronica', 'breakbeat hardcore', 'rave', 'jungle' ]
});
albums.push({
_id: 135,
artistName: 'Johnny Cash',
name: 'Unchained',
releaseDate: '1996, November 5',
genres: [ 'country', 'rock' ]
});
/**********
* 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"}
]
});
});
/**********
* SERVER *
**********/
// listen on port 3000
app.listen(process.env.PORT || 3000, function () {
console.log('Express server is running on http://localhost:3000/');
});