|
|
@@ -9,6 +9,7 @@ var debug = require('debug')('crowi:crowi')
|
|
|
|
|
|
, mongoose = require('mongoose')
|
|
|
|
|
|
+ , helpers = require('./helpers')
|
|
|
, models = require('../models')
|
|
|
;
|
|
|
|
|
|
@@ -18,26 +19,17 @@ function Crowi (rootdir, env)
|
|
|
|
|
|
this.version = pkg.version;
|
|
|
|
|
|
- this.rootDir = rootdir;
|
|
|
- this.pluginDir = path.join(this.rootDir, 'node_modules') + sep;
|
|
|
- this.publicDir = path.join(this.rootDir, 'public') + sep;
|
|
|
- this.libDir = path.join(this.rootDir, 'lib') + sep;
|
|
|
- this.eventsDir = path.join(this.libDir, 'events') + sep;
|
|
|
- this.localeDir = path.join(this.rootDir, 'locales') + sep;
|
|
|
+ this.rootDir = rootdir;
|
|
|
+ this.pluginDir = path.join(this.rootDir, 'node_modules') + sep;
|
|
|
+ this.publicDir = path.join(this.rootDir, 'public') + sep;
|
|
|
+ this.libDir = path.join(this.rootDir, 'lib') + sep;
|
|
|
+ this.eventsDir = path.join(this.libDir, 'events') + sep;
|
|
|
+ this.localeDir = path.join(this.rootDir, 'locales') + sep;
|
|
|
this.resourceDir = path.join(this.rootDir, 'resource') + sep;
|
|
|
- this.viewsDir = path.join(this.libDir, 'views') + sep;
|
|
|
- this.mailDir = path.join(this.viewsDir, 'mail') + sep;
|
|
|
- this.tmpDir = path.join(this.rootDir, 'tmp') + sep;
|
|
|
- this.cacheDir = path.join(this.tmpDir, 'cache');
|
|
|
-
|
|
|
- this.assets = {};
|
|
|
- try {
|
|
|
- var assets = require(this.publicDir + '/js/manifest.json') || {};
|
|
|
- var pluginAssets = require(this.publicDir + '/js/manifest-plugin.json') || {};
|
|
|
- this.assets = Object.assign(assets, pluginAssets);
|
|
|
- } catch (e) {
|
|
|
- // ignore
|
|
|
- }
|
|
|
+ this.viewsDir = path.join(this.libDir, 'views') + sep;
|
|
|
+ this.mailDir = path.join(this.viewsDir, 'mail') + sep;
|
|
|
+ this.tmpDir = path.join(this.rootDir, 'tmp') + sep;
|
|
|
+ this.cacheDir = path.join(this.tmpDir, 'cache');
|
|
|
|
|
|
this.config = {};
|
|
|
this.searcher = null;
|
|
|
@@ -50,6 +42,10 @@ function Crowi (rootdir, env)
|
|
|
|
|
|
this.env = env;
|
|
|
this.node_env = this.env.NODE_ENV || 'development';
|
|
|
+ if (helpers.hasProcessFlag('prod') || helpers.hasProcessFlag('production')) {
|
|
|
+ this.node_env = process.env.NODE_ENV = 'production';
|
|
|
+ }
|
|
|
+
|
|
|
this.port = this.env.PORT || 3000;
|
|
|
|
|
|
this.events = {
|
|
|
@@ -119,23 +115,6 @@ Crowi.prototype.getConfig = function() {
|
|
|
return this.config;
|
|
|
};
|
|
|
|
|
|
-Crowi.prototype.getAssetList = function() {
|
|
|
- if (this.node_env !== 'development') {
|
|
|
- return this.assets;
|
|
|
- }
|
|
|
-
|
|
|
- // reload manifest
|
|
|
- try {
|
|
|
- var assets = require(this.publicDir + '/js/manifest.json') || {};
|
|
|
- var pluginAssets = require(this.publicDir + '/js/manifest-plugin.json') || {};
|
|
|
- this.assets = Object.assign(assets, pluginAssets);
|
|
|
- } catch (e) {
|
|
|
- // ignore
|
|
|
- debug('Failed to reload assets on development', e);
|
|
|
- }
|
|
|
- return this.assets;
|
|
|
-};
|
|
|
-
|
|
|
// getter/setter of model instance
|
|
|
//
|
|
|
Crowi.prototype.model = function(name, model) {
|
|
|
@@ -316,17 +295,33 @@ Crowi.prototype.start = function() {
|
|
|
, server
|
|
|
, io;
|
|
|
|
|
|
- return self.buildServer()
|
|
|
+ return Promise.resolve()
|
|
|
+ .then(function() {
|
|
|
+ return self.init()
|
|
|
+ })
|
|
|
+ .then(function() {
|
|
|
+ return self.buildServer();
|
|
|
+ })
|
|
|
.then(function(app) {
|
|
|
server = http.createServer(app).listen(self.port, function() {
|
|
|
- console.log('[' + self.node_env + '] Express server listening on port ' + self.port);
|
|
|
+ console.log(`[${self.node_env}] Express server listening on port ${self.port}`);
|
|
|
});
|
|
|
|
|
|
+ // setup Live Reload Tools
|
|
|
+ if (self.node_env === 'development') {
|
|
|
+ const CrowiDev = require('./dev');
|
|
|
+ const crowiDev = new CrowiDev(self, server, app);
|
|
|
+ crowiDev.setupTools();
|
|
|
+ }
|
|
|
+
|
|
|
io = require('socket.io')(server);
|
|
|
io.sockets.on('connection', function (socket) {
|
|
|
});
|
|
|
self.io = io;
|
|
|
|
|
|
+ // setup Express Routes
|
|
|
+ self.setupRoutesAtLast(app);
|
|
|
+
|
|
|
return app;
|
|
|
});
|
|
|
};
|
|
|
@@ -347,8 +342,6 @@ Crowi.prototype.buildServer = function() {
|
|
|
require('../plugins')(this, app);
|
|
|
}
|
|
|
|
|
|
- require('../routes')(this, app);
|
|
|
-
|
|
|
if (env == 'development') {
|
|
|
//swig.setDefaults({ cache: false });
|
|
|
app.use(errorHandler({ dumpExceptions: true, showStack: true }));
|
|
|
@@ -367,6 +360,14 @@ Crowi.prototype.buildServer = function() {
|
|
|
return Promise.resolve(app);
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * setup Express Routes
|
|
|
+ * !! this must be at last because it includes '/*' route !!
|
|
|
+ */
|
|
|
+Crowi.prototype.setupRoutesAtLast = function(app) {
|
|
|
+ require('../routes')(this, app);
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* require API for plugins
|
|
|
*
|