-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
47 lines (39 loc) · 1.18 KB
/
app.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
require('dotenv').config()
const cors = require('cors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
const twilio = require('twilio');
var app = express();
app.use(cors());
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.post('/tokens', async (req, res, next) => {
const accessToken = new twilio.jwt.AccessToken(
process.env.TWILIO_ACCOUNT_SID,
process.env.TWILIO_API_KEY_SID,
process.env.TWILIO_API_KEY_SECRET,
{
identity: Math.random().toString(36).substring(2)
}
);
grant = new twilio.jwt.AccessToken.SyncGrant({
serviceSid: process.env.TWILIO_SYNC_SERVICE_SID
});
accessToken.addGrant(grant);
res.send({
token: accessToken.toJwt()
});
});
app.get('/', (req, res) => res.json({ success: true}))
const port = process.env.PORT || 8080
app.listen(port, function () {
console.log('web server listening on port', port)
})