1 | const passport = require('passport');
|
2 | const util = require('./lib/services/util.service');
|
3 | const modelsService = require('./lib/services/models.service');
|
4 | const authService = require('./lib/services/auth.service');
|
5 | const geoService = require('./lib/services/geo.service');
|
6 |
|
7 | const init = (app, options) => {
|
8 |
|
9 | require('./lib/mongoose.js')(options.mongodb_uri);
|
10 |
|
11 | if (options.root_path) {
|
12 | util.setRootPath(options.root_path);
|
13 | }
|
14 |
|
15 | options.models_path = options.models_path ? options.models_path : './app';
|
16 | options.data_path = options.data_path ? options.data_path : './app/data';
|
17 |
|
18 |
|
19 | authService.init(options.authLevels);
|
20 |
|
21 |
|
22 | const modelDefinitions = util.modelDefinitionsSingleLevel(util.getModelDefinitions(options.models_path));
|
23 |
|
24 |
|
25 | const models = modelsService.generateModels(modelDefinitions, options);
|
26 | if (!models.find(m => m.modelName === 'User')) {
|
27 | modelDefinitions.unshift(modelsService.generateUserModel());
|
28 | }
|
29 |
|
30 |
|
31 | const passport_path = options.passport_path ? options.passport_path : './lib/auth/passport';
|
32 | const token_key = options.token_key ? options.token_key : 'NO_KEY_51';
|
33 | require(passport_path)(passport, modelsService.getModel('User'), token_key);
|
34 | app.use(passport.initialize());
|
35 | app.use(passport.session());
|
36 |
|
37 |
|
38 | const routes = require('./lib/routes')(app, modelDefinitions, options, passport);
|
39 | }
|
40 |
|
41 | module.exports = {
|
42 | init: init,
|
43 | getModel: modelsService.getModel,
|
44 | geo: geoService
|
45 | }; |
\ | No newline at end of file |