-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathserver.js
36 lines (33 loc) · 802 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
// ./server.js
/*
* Initialise Express
*/
const express = require('express');
const path = require('path');
const app = express();
const bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname)));
/*
* Initialise Pusher
*/
const Pusher = require('pusher');
const pusher = new Pusher({
appId:'YOUR_PUSHER_APP_ID',
key:'YOUR_PUSHER_APP_KEY',
secret:'YOUR_PUSHER_SECRET',
cluster:'YOUR_CLUSTER'
});
/*
* Define post route for creating new reviews
*/
app.post('/review', (req, res) => {
pusher.trigger('reviews', 'review_added', {review: req.body});
res.status(200).send();
});
/*
* Run app
*/
const port = 5000;
app.listen(port, () => { console.log(`App listening on port ${port}!`)});