Просмотр исходного кода

Change init() and buildServer() interface

Sotaro KARASAWA 10 лет назад
Родитель
Сommit
1a3f0ab6be
2 измененных файлов с 25 добавлено и 24 удалено
  1. 2 2
      app.js
  2. 23 22
      lib/crowi/index.js

+ 2 - 2
app.js

@@ -8,7 +8,7 @@
 var crowi = new (require('./lib/crowi'))(__dirname, process.env);
 
 crowi.init()
-  .then(function(app) {
-    crowi.start(app);
+  .then(function() {
+    return crowi.start();
   }).catch(crowi.exitOnError);
 

+ 23 - 22
lib/crowi/index.js

@@ -7,9 +7,6 @@ var debug = require('debug')('crowi:crowi')
   , sep = path.sep
   , Promise = require('bluebird')
 
-  , http     = require('http')
-  , express  = require('express')
-
   , mongoose    = require('mongoose')
 
   , models = require('../models')
@@ -21,12 +18,13 @@ 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.viewsDir  = path.join(this.libDir, 'views') + sep;
-  this.mailDir   = path.join(this.viewsDir, 'mail') + 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.resourceDir = path.join(this.rootDir, 'resource') + sep;
+  this.viewsDir    = path.join(this.libDir, 'views') + sep;
+  this.mailDir     = path.join(this.viewsDir, 'mail') + sep;
 
   this.config = {};
   this.mailer = {};
@@ -71,8 +69,6 @@ Crowi.prototype.init = function() {
     });
   }).then(function() {
     return self.setupMailer();
-  }).then(function() {
-    return self.buildServer();
   });
 }
 
@@ -182,25 +178,30 @@ Crowi.prototype.setupMailer = function() {
 };
 
 
-Crowi.prototype.start = function(app) {
+Crowi.prototype.start = function() {
   var self = this
+    , http = require('http')
     , server
     , io;
 
-  server = http.createServer(app).listen(self.port, function() {
-    console.log('[' + self.node_env + '] Express server listening on port ' + self.port);
-  });
+  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);
+      });
 
-  io = require('socket.io')(server);
-  io.sockets.on('connection', function (socket) {
-  });
-  this.io = io;
+      io = require('socket.io')(server);
+      io.sockets.on('connection', function (socket) {
+      });
+      self.io = io;
+
+      return app;
+    });
 };
 
 Crowi.prototype.buildServer = function() {
-  var app            = express()
-    , env            = this.node_env
-    , sessionConfig  = this.setupSessionConfig();
+  var express  = require('express')
+    , app = express()
     ;
 
   require('./express-init')(this, app);