ffffng/server/main.js

66 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-06-11 16:27:23 +02:00
#!/usr/bin/env node
2014-05-12 20:08:19 +02:00
/*jslint node: true */
'use strict';
// Dirty hack to allow usage of angular modules.
2016-05-16 13:33:49 +02:00
global.angular = require('ng-di');
2014-05-12 20:08:19 +02:00
angular.module('ffffng', []);
(function () {
// Use graceful-fs instead of fs also in all libraries to have more robust fs handling.
const realFs = require('fs');
const gracefulFs = require('graceful-fs');
gracefulFs.gracefulify(realFs);
})();
2014-05-12 20:08:19 +02:00
require('./config');
2016-05-24 16:40:57 +02:00
require('./logger').tag('main', 'startup').info('Server starting up...');
2014-05-12 20:08:19 +02:00
require('./app');
require('./router');
require('./libs');
require('./utils/databaseUtil');
2014-05-12 20:08:19 +02:00
require('./utils/errorTypes');
require('./utils/resources');
2014-05-12 20:08:19 +02:00
require('./utils/strings');
require('./utils/urlBuilder');
2014-05-12 20:08:19 +02:00
require('./resources/versionResource');
require('./resources/statisticsResource');
2016-06-07 14:08:04 +02:00
require('./resources/frontendResource');
require('./resources/taskResource');
2016-06-11 12:08:50 +02:00
require('./resources/mailResource');
2014-05-12 20:08:19 +02:00
require('./resources/nodeResource');
require('./resources/monitoringResource');
2014-05-12 20:08:19 +02:00
2016-05-20 22:11:35 +02:00
require('./services/mailService');
require('./services/mailTemplateService');
2014-05-12 20:08:19 +02:00
require('./services/nodeService');
require('./services/monitoringService');
2014-05-12 20:08:19 +02:00
require('../shared/validation/constraints');
require('./validation/validator');
2014-05-12 20:08:19 +02:00
require('./jobs/scheduler');
const db = require('./db/database');
db.init().then(() => {
// WARNING: We have to use funtion() syntax here, to satisfy ng-di. m(
2016-05-24 16:40:57 +02:00
angular.injector(['ffffng']).invoke(function (config, app, Logger, Scheduler, Router) {
Logger.tag('main').info('Initializing...');
Scheduler.init();
2016-05-20 22:11:35 +02:00
Router.init();
2014-05-12 20:08:19 +02:00
2016-05-20 22:11:35 +02:00
app.listen(config.server.port, '::');
module.exports = app;
});
}).catch(error => {
console.error('Could not init database: ', error);
process.exit(1);
2014-05-12 20:08:19 +02:00
});