diff --git a/lib/jsgi/rest-store.js b/lib/jsgi/rest-store.js index 1c3b756..530f749 100644 --- a/lib/jsgi/rest-store.js +++ b/lib/jsgi/rest-store.js @@ -94,7 +94,7 @@ exports.RestStore = function(options){ if(range){ // we have to wait for promise for counts to be set (e.g., mongo) responseValue = when(responseValue, function(responseValue){ - return when(responseValue.totalCount, function(count){ + return responseValue && when(responseValue.totalCount, function(count){ delete responseValue.totalCount; var end = start + (responseValue.length || 0) - 1; headers["content-range"] = "items " + start + '-' + end + '/' + (count || '*'); diff --git a/lib/jsgi/templated.js b/lib/jsgi/templated.js index f7b8cae..1c3a3b3 100644 --- a/lib/jsgi/templated.js +++ b/lib/jsgi/templated.js @@ -47,8 +47,9 @@ exports.Templated = function(options, nextApp){ return response; // vanilla HTML -> wrap it in template var vars = ((typeof options.vars === 'function') ? options.vars(request) : options.vars) || {}; - vars.content = media.forEachableToString(response.body); + vars.content = (response.body.forEach) ? media.forEachableToString(response.body) : response.body; //dir('CONTENT', response.body, vars.content); + return exports.render(options.template || 'index.html', vars); var b = exports.renderPartial(options.template || 'index.html', vars); //dir('BODY', b); response.body = b;