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
54
app.js
54
app.js
@ -2,50 +2,38 @@ var express = require('express');
|
|||||||
var favicon = require('serve-favicon');
|
var favicon = require('serve-favicon');
|
||||||
var bodyParser = require('body-parser');
|
var bodyParser = require('body-parser');
|
||||||
var cookieParser = require('cookie-parser');
|
var cookieParser = require('cookie-parser');
|
||||||
|
var validator = require('express-validator');
|
||||||
var log4js = require('log4js');
|
var log4js = require('log4js');
|
||||||
var logger = require('./lib/logger');
|
var logger = require('./lib/logger');
|
||||||
var routes = require('./lib/routes');
|
var routes = require('./lib/routes');
|
||||||
var validator = require('express-validator');
|
|
||||||
var app = express();
|
|
||||||
var router = express.Router(); // eslint-disable-line
|
|
||||||
var baseUriPath = process.env.BASE_URI_PATH || '';
|
|
||||||
|
|
||||||
if (app.get('env') === 'development') {
|
module.exports = function(config) {
|
||||||
app.use(require('errorhandler')());
|
var app = express();
|
||||||
|
var router = express.Router(); // eslint-disable-line
|
||||||
|
var baseUriPath = config.baseUriPath || '';
|
||||||
|
|
||||||
var webpack = require('webpack'),
|
app.use(favicon(__dirname + '/public/favicon.ico'));
|
||||||
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.use(favicon(__dirname + '/public/favicon.ico'));
|
app.set('trust proxy');
|
||||||
|
app.locals.baseUriPath = baseUriPath;
|
||||||
|
|
||||||
app.use(validator([]));
|
app.use(log4js.connectLogger(logger, {
|
||||||
|
format: ':remote-addr :status :method :url :response-timems',
|
||||||
|
level: 'auto' // 3XX=WARN, 4xx/5xx=ERROR
|
||||||
|
}));
|
||||||
|
|
||||||
app.set('trust proxy');
|
app.set('port', config.port);
|
||||||
app.locals.baseUriPath = baseUriPath;
|
|
||||||
|
|
||||||
app.use(log4js.connectLogger(logger, {
|
app.use(baseUriPath, express.static(__dirname + '/public'));
|
||||||
format: ':remote-addr :status :method :url :response-timems',
|
app.use(bodyParser.json({ strict: false }));
|
||||||
level: 'auto' // 3XX=WARN, 4xx/5xx=ERROR
|
|
||||||
}));
|
|
||||||
|
|
||||||
app.set('port', process.env.HTTP_PORT || process.env.PORT || 4242);
|
app.use(cookieParser());
|
||||||
|
|
||||||
app.use(baseUriPath, express.static(__dirname + '/public'));
|
routes.create(router);
|
||||||
app.use(bodyParser.json({ strict: false }));
|
|
||||||
|
|
||||||
app.use(cookieParser());
|
app.use(baseUriPath, router);
|
||||||
|
|
||||||
routes.create(router);
|
return app;
|
||||||
|
};
|
||||||
app.use(baseUriPath, router);
|
|
||||||
|
|
||||||
module.exports = app;
|
|
||||||
|
23
server.js
23
server.js
@ -1,10 +1,31 @@
|
|||||||
var app = require('./app');
|
|
||||||
var logger = require('./lib/logger');
|
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() {
|
var server = app.listen(app.get('port'), function() {
|
||||||
logger.info('unleash started on ' + app.get('port'));
|
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) {
|
process.on('uncaughtException', function(err) {
|
||||||
logger.error('Uncaught Exception:', err.message);
|
logger.error('Uncaught Exception:', err.message);
|
||||||
logger.error(err.stack);
|
logger.error(err.stack);
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
process.env.NODE_ENV = 'test';
|
process.env.NODE_ENV = 'test';
|
||||||
|
|
||||||
var Promise = require('bluebird');
|
var Promise = require('bluebird');
|
||||||
var request = require('supertest');
|
var request = require('supertest');
|
||||||
var app = require('../app');
|
var app = require('../app')({ baseUriPath: '' });
|
||||||
var knex = require('../lib/db/dbPool');
|
var knex = require('../lib/db/dbPool');
|
||||||
var featureDb = require('../lib/db/feature');
|
var featureDb = require('../lib/db/feature');
|
||||||
var strategyDb = require('../lib/db/strategy');
|
var strategyDb = require('../lib/db/strategy');
|
||||||
|
|
||||||
Promise.promisifyAll(request);
|
Promise.promisifyAll(request);
|
||||||
|
Loading…
Reference in New Issue
Block a user