我正在编写一个使用express
并希望swig
用作渲染引擎的应用程序。我以前用过,很好用,但是版本变了,我不知道该怎么办。这是我到目前为止所写的:
网页.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