-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (29 loc) · 1.03 KB
/
index.js
File metadata and controls
36 lines (29 loc) · 1.03 KB
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 bodyParser = require('body-parser');
var path = require('path');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io').listen(http);
// control variables
var port = process.env.PORT || 3000;
var currentDirectory = process.env.PORT ? process.cwd() : __dirname;
// host static files
app.use(express.static(path.join(currentDirectory, 'client')));
app.use('/socket.io', express.static(path.join(currentDirectory, 'node_modules', 'socket.io-client', 'dist')));
// Express configuration for post requests
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
// Twilio facing API
app.post('/receive', (req, res) => {
console.log('Received message', req.body.Body);
// emit an event via socket io
io.emit('new-msg', req.body.Body);
// send twilio a response
res.send('success');
});
// Start HTTP server on port specified in control variables
http.listen(port, () => {
console.log("App is running on port ", port);
});