-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
94 lines (75 loc) · 2.28 KB
/
index.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
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
#!/usr/bin/env node
/*
* Breach: [front] index.js
*
* Copyright (c) 2014, Stanislas Polu. All rights reserved.
*
* @author: spolu
*
* @log:
* - 2014-05-15 spolu Update route
* - 2014-05-02 spolu Creation
*/
"use strict"
var express = require('express');
var util = require('util');
var fs = require('fs');
var http = require('http');
var common = require('./lib/common.js');
var app = express();
var setup = function() {
//
// ### _JSON ROUTES_
//
app.get( '/auth/join', require('./routes/auth.js').get_join);
app.get( '/update', require('./routes/update.js').get_update);
};
// INIT & START
common.log.out('Breach: front [Started]');
common.PG_URL = process.env['BREACH_FRONT_PG_URL'] ||
'postgres://dummy:dummy@localhost/breach_front';
common.log.out('PG_URL: ' + common.PG_URL);
common.PORT = process.env['BREACH_FRONT_PORT'] ?
parseInt(process.env['BREACH_FRONT_PORT'], 10) : 0;
common.log.out('PORT: ' + common.PORT);
common.SECRET = process.env['BREACH_FRONT_SECRET'] || 'dummy';
common.log.out('SECRET: ' + common.SECRET);
common.CIO_SITE_ID = process.env['BREACH_CIO_SITE_ID'] || 'dummy';
common.log.out('CIO_SITE_ID: ' + common.CIO_SITE_ID);
common.CIO_SECRET_KEY = process.env['BREACH_CIO_SECRET_KEY'] || 'dummy';
common.log.out('CIO_SECRET_KEY: ' + common.CIO_SECRET_KEY);
common.pg = new (require('pg').Client)(common.PG_URL);
common.pg.connect(function(err) {
if(err) {
console.log('HERE');
return common.fatal(err);
}
/* App Configuration */
app.use('/', express.static(__dirname + '/app'));
app.use(require('body-parser')());
app.use(require('method-override')())
app.use(function(err, req, res, next) {
common.log.error(err);
return res.send(500, {
error: {
name: err.name,
message: err.message
}
});
});
/* Setup */
setup();
var http_srv = http.createServer(app).listen(common.PORT);
http_srv.on('listening', function() {
var port = http_srv.address().port;
common.log.out('HTTP Server started on port: ' + common.PORT);
});
common.cio = new (require('node-customer.io'))(
common.CIO_SITE_ID,
common.CIO_SECRET_KEY
);
});
// SAFETY NET (kills the process and the spawns)
process.on('uncaughtException', function (err) {
common.fatal(err);
});