Search code examples
expressswig-template

Swig template hangs when called second time


I'm writing an app using express and wished to use swig as rendering engine. I used it before and it was very nice, but the version is changed and I can't figure out what to do. Here is what I've written so far:

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

views/root/home.html

You are at root#home, x = {{ x }}

Now the thing is that when I start server and open localhost:5000/ in browser it correctly shows Your are at root#home, x = 1. But after I make second request localhost:5000/ it just hangs... no reply is coming. In logs I see that the request enters the function and exits it

$ 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

Solution

  • You're using a pre-release version. Expect some hiccups here and there.

    This has been fixed: gh292, gh-291