-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
92 lines (83 loc) · 2.66 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
'use strict';
//Импортируем глобальный объект soshace
require('./app/config');
global.srcRequire = function (name) {
return require(__dirname + '/app/src/' + name);
};
var _ = require('underscore'),
express = require('express'),
Package = require('./package'),
bodyParser = require('body-parser'),
cookieParser = require('cookie-parser'),
session = require('express-session'),
App = express(),
DbConnection = srcRequire('common/dbConnection'),
I18n = require('i18n-2'),
Router = srcRequire('router'),
Passport = require('passport'),
Handlebars = require('express3-handlebars'),
Strategies = srcRequire('common/strategies'),
Class = srcRequire('vendors/class'),
methodOverride = require('method-override'),
SystemMessagesController = srcRequire('controllers/systemMessagesController'),
MongoStore = require('connect-mongo')(session);
var Blog = Class.extend({
/**
* Инициализируем приложение
*
* @private
* @function
* @name Blog.initialize
* @return {undefined}
*/
initialize: function () {
Soshace.DIR_NAME = __dirname;
Soshace.VERSION = Package.version;
Soshace.IS_PRODUCTION = App.get('env') === 'production';
this.configure();
//Подрубаемся к базе
DbConnection.databaseOpen(_.bind(function () {
Strategies.localStrategy();
new Router(App);
App.listen(Soshace.PORT, Soshace.HOST);
}, this));
},
/**
* Конфигурируем наше приложение
*
* @method
* @name Blog.configure
* @return {undefined}
*/
configure: function () {
App.use(bodyParser.json());
App.use(cookieParser());
App.use(methodOverride());
App.enable('view cache');
App.set('views', 'app/views/');
App.engine('hbs', new Handlebars({
layoutsDir: 'app/views/layouts',
partialsDir: 'app/views/partials',
defaultLayout: 'layout',
extname: '.hbs'
}));
App.set('view engine', 'hbs');
I18n.expressBind(App, {
locales: Soshace.LOCALES,
directory: 'app/locales',
extension: '.json',
defaultLocale: Soshace.DEFAULT_LOCALE
});
App.use(session({
secret: Soshace.SESSION_KEY,
saveUninitialized: true,
resave: true,
store: new MongoStore({
db: 'soshace'
})
}));
App.use(Passport.initialize());
App.use(Passport.session());
}
});
void new Blog();