-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
102 lines (88 loc) · 2.21 KB
/
server.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
94
95
96
97
98
99
100
101
102
// BASE SETUP
// =============================================================================
var pongular = require('pongular').pongular;
pongular.module('app', [
'app.libs',
'app.auth',
'app.home',
// 'app.test',
'app.weather',
'app.gpio',
'app.onewire',
'app.cam',
'app.mpd'
])
.uses(
'application/*/config.js',
'application/*/*/*.js'
)
.factory('app',
function($mongoose, $bodyParser, $express, $http, $path, $compression, SocketIo, $config, Auth) {
var db = $mongoose.connect(
$config.get('app.mongodb'),
{
server: {
socketOptions: {
keepAlive: 1
}
}
}
);
db.connection.on('error',console.error.bind(console, 'connection error:'));
//use express.io
var app = $express(),
server = $http.createServer(app);
app.use($bodyParser.urlencoded({extended: true}));
app.use($bodyParser.json());
app.set('view engine', 'ejs');
app.use($compression({threshold : 10}));
app.set('port', process.env.PORT || $config.get('app.port'));
app.use('/tmp/', $express.static('/tmp'));
app.use('/public/', $express.static($path.join(__dirname, 'public')));
app.use('/partials/', $express.static($path.join(__dirname, 'views/partials')));
app.use('/fonts/', $express.static($path.join(__dirname, 'public/bower_components/bootstrap-less/fonts')));
// JWT
app.use('/api', Auth.interceptor());
app.use('/api', Auth.errorHandler());
// socket.io middleware
app.use(SocketIo.create(server));
// auth
// app.use(Auth.bind());
server.listen(app.get('port'),
function(){
console.log('Express server listening on port ' + app.get('port'));
}
);
return app;
}
)
.run(
function(app, AuthRouter, HomeRouter, MpdRouter, WeatherRouter, GpioRouter, CamRouter, SocketIo, CamService, OnewireRouter) {
/**
* Route middlewares
*/
app.use(AuthRouter);
app.use(HomeRouter);
app.use(MpdRouter);
app.use(WeatherRouter);
app.use(GpioRouter);
app.use(CamRouter);
app.use(OnewireRouter);
/**
* Socket.io connection
*/
SocketIo.get().on('connection',
function(socket) {
console.log('SocketIo Client connected!');
}
);
// stop camera on exit
app.on('exit', function() {
CamService.stop();
});
}
);
// init app
pongular.injector([
'app'
]);