forked from TwilioDevEd/call-tracking-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
54 lines (44 loc) · 1.59 KB
/
config.js
File metadata and controls
54 lines (44 loc) · 1.59 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var dotenv = require('dotenv');
dotenv.config({path: '.env'});
var twimlApp = require('./util/twimlApp');
var cfg = {};
// HTTP Port to run our web application
cfg.port = process.env.PORT || 3000;
// A random string that will help generate secure one-time passwords and
// HTTP sessions
cfg.secret = process.env.APP_SECRET || 'keyboard cat';
// Your Twilio account SID and auth token, both found at:
// https://www.twilio.com/user/account
//
// A good practice is to store these string values as system environment
// variables, and load them from there as we are doing below. Alternately,
// you could hard code these values here as strings.
cfg.accountSid = process.env.TWILIO_ACCOUNT_SID;
cfg.authToken = process.env.TWILIO_AUTH_TOKEN;
// Read in a TwiML app SID from the system environment, or create one to use
// in this application
twimlApp.getTwimlAppSid('Call tracking app').then(function(appSid) {
console.log('Working with TwiML App SID: ');
console.log(appSid);
process.env.TWILIO_APP_SID = appSid;
cfg.appSid = process.env.TWILIO_APP_SID;
});
// MongoDB connection string - MONGO_URL is for local dev,
// MONGOLAB_URI is for the MongoLab add-on for Heroku deployment
cfg.mongoUrl = process.env.MONGOLAB_URI || process.env.MONGO_URL;
// Ensure all required configuration is set
var configured = [
cfg.accountSid,
cfg.authToken,
cfg.mongoUrl
].every(function(configValue) {
if (configValue) {
return true;
}
});
if (!configured) {
var s = 'TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, and MONGO_URL must be set';
throw new Error(s);
}
// Export configuration object
module.exports = cfg;