如何在帆中输出玉石?

时间:2013-05-07 22:04:34

标签: pug sails.js

我尝试从帆中输出漂亮的印刷品。我试着像这样配置玉:

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();
};

但它失败了。知道如何正确地做到这一点吗?

3 个答案:

答案 0 :(得分: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();
};

答案 1 :(得分:2)

对于较新版本的Sails(我使用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;
    }
  }
}

作为旁注,我还添加了“漂亮的打印”和#39;作为中间件堆栈的一部分,下面的函数和代码作为config / 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();
}

答案 2 :(得分:0)

尝试设置

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


};
相关问题