mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-20 00:08:02 +01:00
Start injecting config to app.
This commit is contained in:
parent
5282ebfcc9
commit
2355da231e
26
app.js
26
app.js
@ -2,28 +2,15 @@ var express = require('express');
|
||||
var favicon = require('serve-favicon');
|
||||
var bodyParser = require('body-parser');
|
||||
var cookieParser = require('cookie-parser');
|
||||
var validator = require('express-validator');
|
||||
var log4js = require('log4js');
|
||||
var logger = require('./lib/logger');
|
||||
var routes = require('./lib/routes');
|
||||
var validator = require('express-validator');
|
||||
|
||||
module.exports = function(config) {
|
||||
var app = express();
|
||||
var router = express.Router(); // eslint-disable-line
|
||||
var 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));
|
||||
}
|
||||
var baseUriPath = config.baseUriPath || '';
|
||||
|
||||
app.use(favicon(__dirname + '/public/favicon.ico'));
|
||||
|
||||
@ -37,7 +24,7 @@ app.use(log4js.connectLogger(logger, {
|
||||
level: 'auto' // 3XX=WARN, 4xx/5xx=ERROR
|
||||
}));
|
||||
|
||||
app.set('port', process.env.HTTP_PORT || process.env.PORT || 4242);
|
||||
app.set('port', config.port);
|
||||
|
||||
app.use(baseUriPath, express.static(__dirname + '/public'));
|
||||
app.use(bodyParser.json({ strict: false }));
|
||||
@ -48,4 +35,5 @@ routes.create(router);
|
||||
|
||||
app.use(baseUriPath, router);
|
||||
|
||||
module.exports = app;
|
||||
return app;
|
||||
};
|
||||
|
23
server.js
23
server.js
@ -1,10 +1,31 @@
|
||||
var app = require('./app');
|
||||
var logger = require('./lib/logger');
|
||||
|
||||
var config = {
|
||||
baseUriPath: process.env.BASE_URI_PATH || '',
|
||||
port: process.env.HTTP_PORT || process.env.PORT || 4242
|
||||
};
|
||||
|
||||
var app = require('./app')(config);
|
||||
|
||||
var server = app.listen(app.get('port'), function() {
|
||||
logger.info('unleash started on ' + app.get('port'));
|
||||
});
|
||||
|
||||
if (app.get('env') === 'development') {
|
||||
app.use(require('errorhandler')());
|
||||
|
||||
var webpack = require('webpack');
|
||||
var webpackDevMiddleware = require('webpack-dev-middleware');
|
||||
var webpackConfig = require('./webpack.config');
|
||||
var compiler = webpack(webpackConfig);
|
||||
|
||||
app.use(config.baseUriPath, webpackDevMiddleware(compiler, {
|
||||
publicPath: '/js',
|
||||
noInfo: true
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
process.on('uncaughtException', function(err) {
|
||||
logger.error('Uncaught Exception:', err.message);
|
||||
logger.error(err.stack);
|
||||
|
@ -3,7 +3,7 @@ process.env.NODE_ENV = 'test';
|
||||
|
||||
var Promise = require('bluebird');
|
||||
var request = require('supertest');
|
||||
var app = require('../app');
|
||||
var app = require('../app')({ baseUriPath: '' });
|
||||
var knex = require('../lib/db/dbPool');
|
||||
var featureDb = require('../lib/db/feature');
|
||||
var strategyDb = require('../lib/db/strategy');
|
||||
|
Loading…
Reference in New Issue
Block a user