-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
124 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,47 @@ | ||
'use strict'; | ||
|
||
var bodyParser = require('body-parser'); | ||
|
||
/** | ||
* Default module for the initialization of <code>req.body</code> request attribute. | ||
* For initialization of custom parsing module locate the path to the new library. | ||
* | ||
* @example | ||
* conf/app.json | ||
*{ | ||
* | ||
* "server": { | ||
* ... | ||
* "parser": { | ||
* "path": null | ||
* } | ||
* ... | ||
* } | ||
*} | ||
* | ||
* @version 1.0 | ||
* | ||
* @module | ||
* @mixin libs/parser | ||
* | ||
* @return {express.bodyParser} bodyParser JSON request parameters. | ||
* | ||
* @see {@link libs/parser.js} | ||
* @see {@link https://www.npmjs.com/package/body-parser} | ||
* | ||
* @requires body-parser | ||
*/ | ||
function parser() { | ||
return bodyParser.json(); | ||
} | ||
|
||
/** | ||
* @module parser | ||
* @see {@link libs/parser} | ||
*/ | ||
'use strict'; | ||
|
||
var bodyParser = require('body-parser'); | ||
|
||
/** | ||
* Default module for the initialization of <code>req.body</code> request attribute. | ||
* For initialization of custom parsing module locate the path to the new library. | ||
* | ||
* @example | ||
* conf/app.json | ||
*{ | ||
* | ||
* "server": { | ||
* ... | ||
* "parser": { | ||
* "path": null | ||
* } | ||
* ... | ||
* } | ||
*} | ||
* | ||
* @version 1.0 | ||
* | ||
* @module | ||
* @mixin libs/parser | ||
* | ||
* @param {express} app Instance of the application server. | ||
* @param {Object} appconf An application configuration. | ||
* | ||
* @see {@link libs/parser.js} | ||
* @see {@link https://www.npmjs.com/package/body-parser} | ||
* | ||
* @requires body-parser | ||
*/ | ||
function parser(app, appconf) { | ||
// parse application/x-www-form-urlencoded | ||
app.use(bodyParser.urlencoded({ extended: appconf.get('server:parser:extended') || false })); | ||
|
||
// parse application/json | ||
app.use(bodyParser.json()); | ||
} | ||
|
||
/** | ||
* @module parser | ||
* @see {@link libs/parser} | ||
*/ | ||
module.exports = parser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,50 @@ | ||
'use strict'; | ||
|
||
var expressSession = require('express-session'); | ||
|
||
/** | ||
* Default module for the initialization of <code>req.session</code> request attribute. | ||
* For initialization of custom session module locate the path to the new library. | ||
* For security reason recommending update the default <code>session-key</code> value. | ||
* | ||
* @example | ||
* conf/app.json | ||
*{ | ||
* | ||
* "server": { | ||
* ... | ||
* "session": { | ||
* "session-key": "indigojs-session", | ||
* "path": null | ||
* } | ||
* ... | ||
* } | ||
*} | ||
* | ||
* @version 1.0 | ||
* | ||
* @module | ||
* @mixin libs/session | ||
* | ||
* @param {Object} appconf An application configuration. | ||
* @return {express-session} expressSession Instance to the <code>express-session</code> module. | ||
* | ||
* @see {@link libs/session.js} | ||
* @see {@link https://www.npmjs.com/package/express-sessions} | ||
* | ||
* @requires express-session | ||
*/ | ||
function session(appconf) { | ||
var opts = { | ||
secret: appconf.get('server:session:session-key') || 'key_' + new Date().getTime(), | ||
resave: true, | ||
saveUninitialized: true | ||
}; | ||
return expressSession(opts); | ||
} | ||
|
||
/** | ||
* @module session | ||
* @see {@link libs/session} | ||
*/ | ||
'use strict'; | ||
|
||
var expressSession = require('express-session'); | ||
|
||
/** | ||
* Default module for the initialization of <code>req.session</code> request attribute. | ||
* For initialization of custom session module locate the path to the new library. | ||
* For security reason recommending update the default <code>session-key</code> value. | ||
* | ||
* @example | ||
* conf/app.json | ||
*{ | ||
* | ||
* "server": { | ||
* ... | ||
* "session": { | ||
* "session-key": "indigojs-session", | ||
* "path": null | ||
* } | ||
* ... | ||
* } | ||
*} | ||
* | ||
* @version 1.0 | ||
* | ||
* @module | ||
* @mixin libs/session | ||
* | ||
* @param {express} app Instance of the application server. | ||
* @param {Object} appconf An application configuration. | ||
* | ||
* @see {@link libs/session.js} | ||
* @see {@link https://www.npmjs.com/package/express-sessions} | ||
* | ||
* @requires express-session | ||
*/ | ||
function session(app, appconf) { | ||
var opts = { | ||
secret: appconf.get('server:session:session-key') || 'key_' + new Date().getTime(), | ||
resave: true, | ||
saveUninitialized: true | ||
}; | ||
app.use(expressSession(opts)); | ||
} | ||
|
||
/** | ||
* @module session | ||
* @see {@link libs/session} | ||
*/ | ||
module.exports = session; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
'use strict'; | ||
|
||
var session = require('../../../libs/session'); | ||
|
||
describe('libs/session', function () { | ||
|
||
it('should generate default session key', function (done) { | ||
session({ get: function() { | ||
return null; | ||
}}); | ||
done(); | ||
}); | ||
}); | ||
'use strict'; | ||
|
||
var session = require('../../../libs/session'); | ||
|
||
describe('libs/session', function () { | ||
|
||
it('should generate default session key', function (done) { | ||
session({ use: function() {} }, //app | ||
{ get: function() { //appconf | ||
return null; | ||
}}); | ||
done(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters