Skip to content

Commit f45b7a9

Browse files
committed
add cookie-parser && body-parser && favicon
1 parent eedb488 commit f45b7a9

File tree

6 files changed

+51
-1
lines changed

6 files changed

+51
-1
lines changed

app.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ module.exports = function (config) {
4343

4444
var cfg = {
4545
debug: false,
46-
log_enable: false,
46+
favicon: 'favicon.ico',
47+
favicon_enable: false,
48+
post_enable: true,
49+
cookie_enable: true,
50+
log_enable: true,
4751
log_level: "dev",
4852
// "views": "views",
4953
// "routes": "routes",

examples/app.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ var app = require('../')({
44
"views": "views",
55
"routes": "routes",
66
"public": "public",
7+
favicon: 'images/favicon.ico',
8+
favicon_enable: true,
79
before_settings: function(app) {
810
// console.log(app)
911
console.log('before_settings');

examples/public/images/favicon.ico

38.7 KB
Binary file not shown.

lib/body-parser.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var bodyParser = require('body-parser');
2+
3+
module.exports = function (app) {
4+
var post_enable = app.cfg.post_enable;
5+
6+
if (post_enable == true) {
7+
if (app.debug) {
8+
console.log('[DEBUG]: post_enable = ' + post_enable);
9+
}
10+
11+
app.use(bodyParser.json());
12+
app.use(bodyParser.urlencoded({ extended: false }));
13+
}
14+
};

lib/cookie-parser.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var cookieParser = require('cookie-parser');
2+
3+
module.exports = function (app) {
4+
var cookie_enable = app.cfg.cookie_enable;
5+
6+
if (app.cfg['cookie_enable'] == true) {
7+
if (app.debug) {
8+
console.log('[DEBUG]: cookie_enable = ' + cookie_enable);
9+
}
10+
11+
app.use(cookieParser());
12+
}
13+
};

lib/favicon.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var path = require('path');
2+
var favicon = require('serve-favicon');
3+
4+
module.exports = function (app) {
5+
var log_level = app.cfg.log_level;
6+
7+
if (app.cfg['public'] && app.cfg['favicon_enable'] && app.cfg['favicon']) {
8+
var p = path.join(app.get('public'), app.cfg['favicon']);
9+
10+
if (app.debug) {
11+
console.log('[DEBUG]: favicon = ' + p);
12+
}
13+
14+
// uncomment after placing your favicon in /public
15+
app.use(favicon(p));
16+
}
17+
};

0 commit comments

Comments
 (0)