2013-05-07 63 views
1

我嘗試從帆中輸出漂亮的印花。我試圖配置玉像這樣:如何在帆中輸出漂亮的印花?

module.exports.bootstrap = function (cb) { 
    // Development environment 
    if (sails.config.environment === 'development') { 

     sails.config.express.customMiddleware = function() { 
      var app = sails.express.app; 
      app.set('view options', { pretty:true }); 
      // app.locals.pretty = true; 
     } 
    } 
    cb(); 
}; 

,但它失敗。任何想法如何正確地做到這一點?

回答

0

嘗試設置

module.exports.express.customMiddleware = function() { 


}; 
2

這對我的作品。

module.exports.bootstrap = function (cb) { 

    // Development environment 
    if (sails.config.environment === 'development') { 

     console.log('development --------'); 
     var app = sails.express.app; 
     app.set('view options', { pretty:true }); 
     app.locals.pretty = true; 

    } 

    cb(); 
}; 
2

對於帆船的新版本(我使用v0.11.0-RC4,本次發行前0.11支),sails.express.app不起作用。讀完Sails' Middleware documentation之後,我將下面的代碼添加到local.js中,並按需要工作。請記住,具有http.customMiddleware函數的其他配置文件將通過將其添加到local.js來覆蓋/被覆蓋。

http: { 
    customMiddleware: function(app) { 
    if (sails.config.environment === 'development') { 
     app.set('view options', {pretty: true}); 
     app.locals.pretty = true; 
    } 
    } 
} 

作爲邊注,我還增加了「prettyPrint」功能和代碼下面的配置/ http.js文件作爲中間件棧的一部分。在我看來,它似乎更適合local.js(上面的代碼)。

// have JADE output nicely on development 
prettyPrint: function (req, res, next) { 
    if (sails.config.environment === 'development') { 
    req.app.set('view options', {pretty: true}); 
    req.app.locals.pretty = true; 
    } 
    return next(); 
}