を使用してアプリケーションを作成しており、レンダリング エンジンとして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
。しかし、2回目のリクエストを行った後、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