-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (58 loc) · 2.09 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*eslint no-console: 0*/
'use strict';
var express = require('express')
, expressValidator = require('express-validator')
, kraken = require('kraken-js')
, bodyParser = require('body-parser')
, methodOverride = require('method-override')
, logger = require('winston')
;
var externalConfigLib=require('./lib/externalConfigLib')
, loggerLib=require('./lib/loggerLib')
;
var options, app;
app = module.exports = express();
/**
* Activation du RESTFULL (get, post, put et delete) pour les controllers
* NOTE: when using req.body, you must fully parse the request body
* before you call methodOverride() in your middleware stack,
* otherwise req.body will not be populated.
*/
app.use(bodyParser.urlencoded({ extended: true }));
app.use(methodOverride(
function(req /*, res*/){
if (req.body && typeof req.body === 'object' && '_method' in req.body) {
// look in urlencoded POST bodies and delete it
var method = req.body._method;
delete req.body._method;
return method;
}
}
));
// expressValidator must be immediately after express.bodyParser()!
app.use(expressValidator(require('./lib/expressValidatorLib')));
/*
* Create and configure application. Also exports application instance for use by tests.
* See https://github.com/krakenjs/kraken-js#options for additional configuration options.
*/
options = {
onconfig: function (config, next) {
/*
* Add any additional config setup or overrides here. `config` is an initialized
* `confit` (https://github.com/krakenjs/confit/) configuration object.
*/
externalConfigLib.configureAsync(config)
.then(function(){
return loggerLib.configureAsync(config.get('loggerConfig'));
}).then(function(){
return next(null, config);
}).catch(function(err){
if (err) { return next(err) ; }
});
}
};
app.use(kraken(options));
app.on('start', function () {
logger.log('Application ready to serve requests.');
logger.log('Environment: %s', app.kraken.get('env:env'));
});