-
Notifications
You must be signed in to change notification settings - Fork 17
/
server.js
43 lines (35 loc) · 995 Bytes
/
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
var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var Pusher = require('pusher');
var pusher = new Pusher({
appId: '<your-app-id>',
key: '<your-api-key>',
secret: '<your-app-secret>',
cluster: 'ap2',
encrypted: true
});
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
app.post('/comment', function(req, res){
console.log(req.body);
var newComment = {
name: req.body.name,
email: req.body.email,
comment: req.body.comment
}
pusher.trigger('flash-comments', 'new_comment', newComment);
res.json({ created: true });
});
// Error Handler for 404 Pages
app.use(function(req, res, next) {
var error404 = new Error('Route Not Found');
error404.status = 404;
next(error404);
});
module.exports = app;
app.listen(9000, function(){
console.log('Example app listening on port 9000!')
});