How to add to the "viewing options" in Express?

I am studying using Express. I want to do:

app.configure(function(){
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.set('view options', { layout: false });    /* asterisk */
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);                           /* dagger */
  app.use(express.static(__dirname + '/public'));
});

app.configure('development', function(){
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
  app.use(express.logger('dev'));
  app.set('view options', { pretty: true });     /* asterisk */
});

The additions I made were:

  • use 'layout: false' for Jade.
  • pretty-print HTML in jade.
  • turn on the recorder, in the format 'dev'

There are two problems:

  • /* asterisk */When I set "pretty: true", I override my previous options, rather than adding to them. Ie, my program is interrupted if I do not add { pretty: true, layout: false }, which feels redundant and may not be right. How can I fix it so that I only “change” the view parameters and not “determine” them?

  • /* dagger */ , /favicon.ico. , app.use(app.router);, /, /favicon.ico. ?

+3
2

- , app.set . , , view options . , , , . , , , package.json:

"dependencies": {
  "express": "2.5.5"
, "jade": ">= 0.0.1"
, "connect": "1.X"
}

utils:

var utils = require('connect').utils;

app.set(option) , , view option, :

app.set('view options', utils.merge(app.set('view options'), { pretty: true }));

, , , app.use . , , , , , .

router, URL- '/', logger . , favicon.ico -, , ( static , public/favicon.ico), logger .

, logger , router.

+2

Express 3.x, app.set('view options') . https://github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x app.js app.locals,

app.locals.pretty = true;

ejs

app.locals.open = '}}';
app.locals.close = '{{';
+5

All Articles