Fix call to res.write before res.end