Skip to content
This repository was archived by the owner on Feb 5, 2024. It is now read-only.

Commit 1a3f0ab

Browse files
committed
Change init() and buildServer() interface
1 parent 6257212 commit 1a3f0ab

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

app.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
var crowi = new (require('./lib/crowi'))(__dirname, process.env);
99

1010
crowi.init()
11-
.then(function(app) {
12-
crowi.start(app);
11+
.then(function() {
12+
return crowi.start();
1313
}).catch(crowi.exitOnError);
1414

lib/crowi/index.js

+23-22
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ var debug = require('debug')('crowi:crowi')
77
, sep = path.sep
88
, Promise = require('bluebird')
99

10-
, http = require('http')
11-
, express = require('express')
12-
1310
, mongoose = require('mongoose')
1411

1512
, models = require('../models')
@@ -21,12 +18,13 @@ function Crowi (rootdir, env)
2118

2219
this.version = pkg.version;
2320

24-
this.rootDir = rootdir;
25-
this.pluginDir = path.join(this.rootDir, 'node_modules') + sep;
26-
this.publicDir = path.join(this.rootDir, 'public') + sep;
27-
this.libDir = path.join(this.rootDir, 'lib') + sep;
28-
this.viewsDir = path.join(this.libDir, 'views') + sep;
29-
this.mailDir = path.join(this.viewsDir, 'mail') + sep;
21+
this.rootDir = rootdir;
22+
this.pluginDir = path.join(this.rootDir, 'node_modules') + sep;
23+
this.publicDir = path.join(this.rootDir, 'public') + sep;
24+
this.libDir = path.join(this.rootDir, 'lib') + sep;
25+
this.resourceDir = path.join(this.rootDir, 'resource') + sep;
26+
this.viewsDir = path.join(this.libDir, 'views') + sep;
27+
this.mailDir = path.join(this.viewsDir, 'mail') + sep;
3028

3129
this.config = {};
3230
this.mailer = {};
@@ -71,8 +69,6 @@ Crowi.prototype.init = function() {
7169
});
7270
}).then(function() {
7371
return self.setupMailer();
74-
}).then(function() {
75-
return self.buildServer();
7672
});
7773
}
7874

@@ -182,25 +178,30 @@ Crowi.prototype.setupMailer = function() {
182178
};
183179

184180

185-
Crowi.prototype.start = function(app) {
181+
Crowi.prototype.start = function() {
186182
var self = this
183+
, http = require('http')
187184
, server
188185
, io;
189186

190-
server = http.createServer(app).listen(self.port, function() {
191-
console.log('[' + self.node_env + '] Express server listening on port ' + self.port);
192-
});
187+
return self.buildServer()
188+
.then(function(app) {
189+
server = http.createServer(app).listen(self.port, function() {
190+
console.log('[' + self.node_env + '] Express server listening on port ' + self.port);
191+
});
193192

194-
io = require('socket.io')(server);
195-
io.sockets.on('connection', function (socket) {
196-
});
197-
this.io = io;
193+
io = require('socket.io')(server);
194+
io.sockets.on('connection', function (socket) {
195+
});
196+
self.io = io;
197+
198+
return app;
199+
});
198200
};
199201

200202
Crowi.prototype.buildServer = function() {
201-
var app = express()
202-
, env = this.node_env
203-
, sessionConfig = this.setupSessionConfig();
203+
var express = require('express')
204+
, app = express()
204205
;
205206

206207
require('./express-init')(this, app);

0 commit comments

Comments
 (0)