forked from SantoshSrinivas79/myyna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
130 lines (110 loc) · 4.03 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* Sleek app init
* Here we iniialize :: Its better to dont edit, if you're a beginner :)
*
* @package Sleek.js
* @version 1.0
*
* The MIT License (MIT)
* Copyright Cubet Techno Labs, Cochin (c) <2013> <[email protected]>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author Robin <[email protected]>
* @Date 23-10-2013
*/
//require our needs
var express = require('express');
var http = require('http');
var path = require('path');
var exphbs = require('express-handlebars');
var helmet = require('helmet');
var fs = require('fs');
var hbs = require('handlebars');
var engines = require('consolidate');
global.app = express();
global.sleekConfig = {};
require(path.join(__dirname,'application/config/config.js'));
var favicon = require('serve-favicon');
var logger = require('morgan');
var methodOverride = require('method-override');
var session = require('express-session');
var bodyParser = require('body-parser');
//json = require('json'),
//urlencoded = require('urlencode'),
var multer = require('multer');
var upload = multer({ dest: './uploads' });
var cookieParser = require('cookie-parser');
var static = require('serve-static')
var errorHandler = require('errorhandler');
var app = express();
app.set('env', sleekConfig.env || process.env.NODE_ENV);
// all environments
app.set('port', process.env.PORT || sleekConfig.appPort);
app.set('host', sleekConfig.appHost ? sleekConfig.appHost : 'localhost');
app.set('views', path.join(__dirname, 'application/views'));
app.set('view engine', 'handlebars');
app.engine('html', exphbs({
defaultLayout: 'default',
layoutsDir: path.join(__dirname, 'application/layouts/'),
extname:".html"
})
);
app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(static(path.join(__dirname, 'public')));
app.use(static(path.join(__dirname, 'uploads')));
app.use(methodOverride());
app.use(cookieParser('CubEtNoDeSlEek'))
app.use(session({ resave: true,
saveUninitialized: true,
secret: 'CubEtNoDeSlEek' }));
app.use(helmet());
app.set('strict routing');
//set Site url
global.sleekConfig.siteUrl = app.get('host')+':'+app.get('port');
//get configs
var sFolderPath = path.join(__dirname, 'install');
var cur_directory = path.join(__dirname, '');
fs.exists(sFolderPath, function(exists) {
if (!exists){
require('./system/core/sleek.js')(app);
}
else
{
require('./system/install/route.js')(app,sFolderPath,cur_directory);
}
});
// development only
if ('development' == app.get('env')) {
app.use(errorHandler());
} else {
//prevent crash
process.on('uncaughtException', function (exception) {
console.log(exception);
});
}
try {
var server = http.createServer(app);
global.sio = require('socket.io')(server);
server.listen(app.get('port'), function(){
console.log('application running at ' + sleekConfig.siteUrl);
});
} catch (e) {
console.error(e);
}