我正在尝试将 Jade 替换为Bliss作为 NodeJS 上示例 Express 网站的模板引擎。这是 app.js 的内容:
var express = require('express'),
routes = require('./routes'),
http = require('http'),
path = require('path'),
Bliss = new require('bliss'),
bliss = new Bliss({ext: '.jhtml'}),
app = express();
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
// app.set('view engine', 'bliss'); /* replaced with app.engine() call below */
app.use(express.favicon(__dirname + '/public/img/favicon.ico'));
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(require('stylus').middleware(__dirname + '/public'));
app.use(express.static(path.join(__dirname, 'public'))); });
app.configure('development', function(){
app.use(express.errorHandler());
app.locals.pretty = true; });
app.get('/', /* routes.index */ function(req, res){
var index = bliss.compile('index');
bliss.render(index); });
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port')); });
我从其他 SO 问题中尝试了一些东西,但我对 Node、Express 或 Bliss 还不够熟悉,无法调试它为什么返回以下 500 错误:
500 TypeError: Object function anonymous() { var __out=[],write=__out.push.bind(__out),__tmp=0,render=this.render;write("index"); return __out.join(''); } has no method 'indexOf'
我相当有信心模板和视图设置正确,因为它们非常简单并且密切关注 Bliss wiki。
这是因为 Bliss 与 Express 不完全兼容吗?有没有更好的方法来设置它正常工作?