我正在使用express
编写应用,并希望使用swig
作为渲染引擎。我之前使用它并且它非常好,但版本已更改,我无法弄清楚该怎么做。这是我到目前为止所写的内容:
web.js
var express = require('express');
var app = express();
var swig = require('swig'); // rendering engine
app.engine('html', swig.renderFile);
app.set('view engine', 'html');
app.set('views', __dirname + '/views');
app.use(express.static(__dirname + '/public'));
app.use(express.bodyParser());
app.use(express.logger());
app.get('/', function (req, res) {
console.log('--> root#home');
res.render('root/home.html', { x: 1 });
console.log('<-- root#home');
});
var port = process.env.PORT || 5000;
app.listen(port, function() {
console.log("Listening on " + port);
});
视图/根/ home.html做为
You are at root#home, x = {{ x }}
现在问题是,当我启动服务器并在浏览器中打开localhost:5000/
时,它会正确显示Your are at root#home, x = 1
。但在我发出第二个请求localhost:5000/
之后,它就会挂起......没有回复。在日志中,我看到请求进入函数并退出
$ foreman start
15:19:14 web.1 | started with pid 985
15:19:14 web.1 | Listening on 5000
15:19:17 web.1 | --> root#home // ** first time **
15:19:17 web.1 | <-- root#home
15:19:17 web.1 | 127.0.0.1 - - [Tue, 20 Aug 2013 11:19:17 GMT] "GET / HTTP/1.1" 200 26 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:23.0) Gecko/20100101 Firefox/23.0"
15:19:19 web.1 | --> root#home // ** second time **
15:19:19 web.1 | <-- root#home
^CSIGINT received