-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
120 lines (96 loc) · 2.6 KB
/
setup.js
File metadata and controls
120 lines (96 loc) · 2.6 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
var _ = require('underscore');
module.exports = {
config: function () {
var fs =require('fs');
var CONFIG_FILE = process.env.CONFIG_FILE || './config';
try {
this.config = require(CONFIG_FILE);
} catch (e) {
function camelToCaps (str) {
return str.replace(/([A-Z])/g, function($1) {
return "_" + $1;
}).toUpperCase();
}
var sampleConfig = require('./config.sample.js');
this.config = {};
_.each(sampleConfig, function (val, moduleKey) {
if (!_.isObject(val)) {
this.config[moduleKey] = process.env[camelToCaps(moduleKey)] || val;
return;
}
this.config[moduleKey] = {};
_.each(val, function (defaultVal, optionKey) {
this.config[moduleKey][optionKey] =
process.env[camelToCaps(moduleKey) + '_' + camelToCaps(optionKey)] || val;
}, this);
}, this);
}
},
logging: function () {
var winston = require('winston');
this.logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)(),
new (winston.transports.File)({
filename: this.config.logFile
})
]
});
},
server: function () {
var express = require('express');
var http = require('http');
var bodyParser = require('body-parser');
this.app = express()
.use(express.static(__dirname + '/public'))
.use(bodyParser.json({
}));
this.server = http
.Server(this.app)
.listen(this.config.port);
},
pushState: function () {
this.app.get('*', function(req, res){
res.sendFile(__dirname + '/public/index.html');
});
},
twilio: function () {
var twilio = require('twilio');
this.twilioClient = twilio(
this.config.twilio.accountSid,
this.config.twilio.authToken
);
},
socket: function () {
var socket = require('socket.io');
var io = socket(this.server);
this.socket = {};
io.on('connection', _.bind(function (socket) {
var uniqueId = _.random(0, 100000000);
this.socket[uniqueId] = socket;
socket.emit('id', uniqueId);
}, this));
},
mailgun: function () {
var Mailgun = require('mailgun').Mailgun;
this.mailgun = new Mailgun(this.config.mailgun.key);
},
localTunnel: function () {
var localtunnel = require('localtunnel');
if (!this.config.rootUrl) {
localtunnel(this.config.port, _.bind(function (err, tunnel) {
this.config.rootUrl = tunnel.url;
this.logger.info('LocalTunnel URL: ' + this.config.rootUrl);
}, this));
}
},
parse: function () {
var Parse = require('parse/node');
Parse.initialize(
this.config.parse.appKey,
this.config.parse.jsKey,
this.config.parse.masterKey
);
Parse.Cloud.useMasterKey();
}
};