|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -module.exports = function (_instance) { |
4 | | - var Express = require('express') |
5 | | - , bodyParser = require('body-parser') |
6 | | - , expressApplication = new Express(); |
| 3 | +const _ = require('underscore'); |
| 4 | +const Express = require('express'); |
| 5 | +const BodyParser = require('body-parser'); |
| 6 | + |
| 7 | +module.exports = async function (instance) { |
| 8 | + let expressApplication = new Express(); |
7 | 9 |
|
8 | 10 | // X-Powered-By: bool.js |
9 | 11 | expressApplication.use(function (req, res, next) { |
10 | 12 | res.header('X-Powered-By', 'booljs'); |
11 | 13 | next(); |
12 | 14 | }); |
13 | 15 |
|
14 | | - var config = _instance.getComponents().configuration.get('server'); |
| 16 | + var configuration = instance.getComponents().configuration.get('server'); |
15 | 17 |
|
16 | 18 | // Sets listening hostname |
17 | | - expressApplication.set( |
18 | | - 'host', |
19 | | - process.env.IP || process.env.HOSTNAME || process.env.HOST || |
20 | | - ( config && ( |
21 | | - config.ip || config.hostname || config.host |
22 | | - )) || '0.0.0.0' |
23 | | - ); |
| 19 | + expressApplication.set('host', ( |
| 20 | + process.env.IP || process.env.HOSTNAME || process.env.HOST || |
| 21 | + (configuration && ( |
| 22 | + configuration.ip || configuration.hostname || configuration.host |
| 23 | + )) || |
| 24 | + '0.0.0.0' |
| 25 | + )); |
24 | 26 |
|
25 | 27 | // Sets listening port |
26 | | - expressApplication.set( |
27 | | - 'port', |
28 | | - process.env.PORT || |
29 | | - ( config && |
30 | | - config.port |
31 | | - ) || 3001 |
32 | | - ); |
| 28 | + expressApplication.set('port', ( |
| 29 | + process.env.PORT || (configuration && configuration.port) || 3001 |
| 30 | + )); |
33 | 31 |
|
34 | 32 | // Enable body-parser middlewares |
35 | | - var bodyParserOptions = (config && config.body) || undefined; |
| 33 | + var bodyParserOptions = (configuration && configuration.body) || undefined; |
36 | 34 |
|
37 | | - if(bodyParserOptions !== undefined) { |
38 | | - expressApplication.use(bodyParser.urlencoded(_.extend({ |
39 | | - extended: true |
40 | | - }, bodyParserOptions))); |
41 | | - expressApplication.use(bodyParser.json(bodyParserOptions)); |
| 35 | + if (bodyParserOptions !== undefined) { |
| 36 | + expressApplication.use(BodyParser.urlencoded( |
| 37 | + _.extend({ extended: true }, bodyParserOptions)) |
| 38 | + ); |
| 39 | + expressApplication.use(BodyParser.json(bodyParserOptions)); |
42 | 40 | } else { |
43 | | - expressApplication.use(bodyParser.urlencoded({ extended: true })); |
44 | | - expressApplication.use(bodyParser.json()); |
| 41 | + expressApplication.use(BodyParser.urlencoded({ extended: true })); |
| 42 | + expressApplication.use(BodyParser.json()); |
45 | 43 | } |
46 | 44 |
|
47 | 45 | // Enables Json View |
48 | | - if(!_instance.getComponents().views){ |
49 | | - _instance.insertComponent('views', {}); |
| 46 | + if (!instance.getComponents().views) { |
| 47 | + instance.insertComponent('views', {}); |
50 | 48 | } |
51 | | - _instance.insertComponent( |
52 | | - 'Json', require('../views/json'), _instance.getComponents().views |
| 49 | + |
| 50 | + instance.insertComponent( |
| 51 | + 'Json', require('../views/json'), instance.getComponents().views |
53 | 52 | ); |
54 | 53 |
|
55 | | - return q.resolve(expressApplication); |
| 54 | + return expressApplication; |
56 | 55 | }; |
0 commit comments