1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

Split app and server. No need to start the server for these tests.

This commit is contained in:
Jari Bakken 2014-12-03 15:22:03 +01:00 committed by Ivar Conradi Østhus
parent 0047d52ef4
commit 2f0cddd45b
3 changed files with 52 additions and 47 deletions

46
app.js Normal file
View File

@ -0,0 +1,46 @@
var express = require('express'),
bodyParser = require('body-parser'),
log4js = require('log4js'),
logger = require('./lib/logger'),
routes = require('./lib/routes'),
eventApi = require('./lib/eventApi'),
featureApi = require('./lib/featureApi'),
strategyApi = require('./lib/strategyApi'),
validator = require('express-validator'),
app = express(),
router = express.Router(),
baseUriPath = process.env.BASE_URI_PATH || '';
if(app.get('env') === 'development') {
app.use(require('errorhandler')());
var webpack = require('webpack'),
webpackDevMiddleware = require('webpack-dev-middleware'),
webpackConfig = require('./webpack.config'),
compiler = webpack(webpackConfig),
config = {
publicPath: '/js',
noInfo: true
};
app.use(baseUriPath, webpackDevMiddleware(compiler, config));
}
app.use(validator([]));
app.set('trust proxy');
app.locals.baseUriPath = baseUriPath;
app.use(log4js.connectLogger(logger, {format: ':remote-addr :status :method :url :response-timems'}));
app.set('port', process.env.HTTP_PORT || process.env.PORT || 4242);
app.use(baseUriPath, express.static(__dirname + '/public'));
app.use(bodyParser.json({strict: false}));
eventApi(router);
featureApi(router);
strategyApi(router);
routes(router);
app.use(baseUriPath, router);
module.exports = app;

View File

@ -1,47 +1,5 @@
var express = require('express'),
bodyParser = require('body-parser'),
log4js = require('log4js'),
logger = require('./lib/logger'),
routes = require('./lib/routes'),
eventApi = require('./lib/eventApi'),
featureApi = require('./lib/featureApi'),
strategyApi = require('./lib/strategyApi'),
validator = require('express-validator'),
app = express(),
router = express.Router(),
baseUriPath = process.env.BASE_URI_PATH || '';
if(app.get('env') === 'development') {
app.use(require('errorhandler')());
var webpack = require('webpack'),
webpackDevMiddleware = require('webpack-dev-middleware'),
webpackConfig = require('./webpack.config'),
compiler = webpack(webpackConfig),
config = {
publicPath: '/js',
noInfo: true
};
app.use(baseUriPath, webpackDevMiddleware(compiler, config));
}
app.use(validator([]));
app.set('trust proxy');
app.locals.baseUriPath = baseUriPath;
app.use(log4js.connectLogger(logger, {format: ':remote-addr :status :method :url :response-timems'}));
app.set('port', process.env.HTTP_PORT || process.env.PORT || 4242);
app.use(baseUriPath, express.static(__dirname + '/public'));
app.use(bodyParser.json({strict: false}));
eventApi(router);
featureApi(router);
strategyApi(router);
routes(router);
app.use(baseUriPath, router);
var app = require('./app');
var logger = require('./lib/logger');
var server = app.listen(app.get('port'), function() {
logger.info('unleash started on ' + app.get('port'));
@ -52,7 +10,6 @@ process.on('uncaughtException', function(err) {
logger.error(err.stack);
});
module.exports = {
app: app,
server: server

View File

@ -1,6 +1,8 @@
var request = require('supertest');
var mockery = require('mockery');
process.env.NODE_ENV = 'test';
var server;
function setupMockServer() {
@ -14,9 +16,9 @@ function setupMockServer() {
mockery.registerSubstitute('./featureDb', '../test/featureDbMock');
mockery.registerSubstitute('./strategyDb', '../test/strategyDbMock');
server = require('../server');
var app = require('../app');
return request('http://localhost:' + server.app.get('port'));
return request(app);
}
function tearDownMockServer() {