mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	
						commit
						c5ff16a19c
					
				@ -23,6 +23,11 @@ module.exports = function (config) {
 | 
				
			|||||||
    app.set('trust proxy');
 | 
					    app.set('trust proxy');
 | 
				
			||||||
    app.set('port', config.port);
 | 
					    app.set('port', config.port);
 | 
				
			||||||
    app.locals.baseUriPath = baseUriPath;
 | 
					    app.locals.baseUriPath = baseUriPath;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (typeof config.preHook === 'function') {
 | 
				
			||||||
 | 
					        config.preHook(app);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    app.use(cookieParser());
 | 
					    app.use(cookieParser());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (publicFolder) {
 | 
					    if (publicFolder) {
 | 
				
			||||||
@ -49,6 +54,10 @@ module.exports = function (config) {
 | 
				
			|||||||
        }));
 | 
					        }));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (typeof config.preRouterHook === 'function') {
 | 
				
			||||||
 | 
					        config.preRouterHook(app);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Setup API routes
 | 
					    // Setup API routes
 | 
				
			||||||
    const apiRouter = express.Router(); // eslint-disable-line new-cap
 | 
					    const apiRouter = express.Router(); // eslint-disable-line new-cap
 | 
				
			||||||
    routes.createAPI(apiRouter, config);
 | 
					    routes.createAPI(apiRouter, config);
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										31
									
								
								lib/app.test.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								lib/app.test.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					'use strict';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const test = require('ava');
 | 
				
			||||||
 | 
					const proxyquire = require('proxyquire');
 | 
				
			||||||
 | 
					const getApp = proxyquire('./app', {
 | 
				
			||||||
 | 
					    './routes': {
 | 
				
			||||||
 | 
					        createAPI: () => {},
 | 
				
			||||||
 | 
					        createLegacy: () => {},
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test('should not throw when valid config', t => {
 | 
				
			||||||
 | 
					    const app = getApp({});
 | 
				
			||||||
 | 
					    t.true(typeof app.listen === 'function');
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test('should call preHook', t => {
 | 
				
			||||||
 | 
					    let called = 0;
 | 
				
			||||||
 | 
					    getApp({ preHook: () => {
 | 
				
			||||||
 | 
					        called++;
 | 
				
			||||||
 | 
					    } });
 | 
				
			||||||
 | 
					    t.true(called === 1);
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test('should call preRouterHook', t => {
 | 
				
			||||||
 | 
					    let called = 0;
 | 
				
			||||||
 | 
					    getApp({ preRouterHook: () => {
 | 
				
			||||||
 | 
					        called++;
 | 
				
			||||||
 | 
					    } });
 | 
				
			||||||
 | 
					    t.true(called === 1);
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
@ -85,6 +85,7 @@
 | 
				
			|||||||
    "eslint": "^3.11.1",
 | 
					    "eslint": "^3.11.1",
 | 
				
			||||||
    "eslint-config-finn": "^1.0.0-beta.1",
 | 
					    "eslint-config-finn": "^1.0.0-beta.1",
 | 
				
			||||||
    "nyc": "^9.0.1",
 | 
					    "nyc": "^9.0.1",
 | 
				
			||||||
 | 
					    "proxyquire": "^1.7.10",
 | 
				
			||||||
    "sinon": "^1.17.5",
 | 
					    "sinon": "^1.17.5",
 | 
				
			||||||
    "superagent": "^2.3.0",
 | 
					    "superagent": "^2.3.0",
 | 
				
			||||||
    "supertest": "^2.0.1",
 | 
					    "supertest": "^2.0.1",
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user