-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
110 lines (89 loc) · 2.98 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
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
//----------------------------------------------------------//
//
// Loading dependencies
//
//----------------------------------------------------------//
var express = require('express');
var session = require('express-session');
var fs = require('fs');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var qt = require('quickthumb');
var cfg = require('config');
var bugsnag = require('bugsnag');
//----------------------------------------------------------//
//
// Loading Routes
//
//----------------------------------------------------------//
var routes = require('./routes/index');
var authR = require('./routes/auth');
//----------------------------------------------------------//
//
// Initialize express app
//
//----------------------------------------------------------//
var app = express();
//----------------------------------------------------------//
//
// Express configuration
//
//----------------------------------------------------------//
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
//----------------------------------------------------------//
//
// 3rd-party service configuration
//
//----------------------------------------------------------//
bugsnag.register(cfg.bugsnag.key);
//----------------------------------------------------------//
//
// Common middleware
//
//----------------------------------------------------------//
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
var logFile = fs.createWriteStream('./myLogFile.log', {flags: 'a'}); //use {flags: 'w'} to open in write mode
app.use(logger("combined", {stream: logFile}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
// Use quickthumb
app.use(qt.static(__dirname + '/'));
//----------------------------------------------------------//
//
// Socket configuration
//
//----------------------------------------------------------//
var server = require('http').Server(app);
//----------------------------------------------------------//
//
// Attaching routes handlers
//
//----------------------------------------------------------//
app.use('/', routes);
app.use('/auth', authR);
//----------------------------------------------------------//
//
// System Error Handlers
//
//----------------------------------------------------------//
app.use(function(err, req, res, next) {
bugsnag.notify(new Error("General Server Error"), {err:{message:err.message, stack:err.stack}});
res.status(err.status || 500);
res.json({status:0, code:1000, message:"Server Error"});
});
//----------------------------------------------------------//
//
// System Export
//
//----------------------------------------------------------//
module.exports = {
app:app,
server:server
};