-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
36 lines (29 loc) · 870 Bytes
/
index.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
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.sendFile(__dirname + '/home.html');
});
var COMMENTS = [
{
"author": "Pete Hunt",
"text": "Hey there!"
},
{
"author": "Paul O’Shannessy",
"text": "React is *great*!"
}
];
app.get('/api/comments', function (req, res) {
res.json(COMMENTS);
});
app.post('/api/comments', function (req, res) {
console.log('WTF', req.body);
COMMENTS.push(req.body ? req.body : {author: 'no data', text: 'no data was received'});
res.json(COMMENTS);
});
app.use('/static', express.static('static'));
var server = app.listen(process.env.GUN_PORT || 8080, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});