Skip to content
Browse files

Fixed bugs in install and routing

  • Loading branch information...
1 parent 097a498 commit 7edc0eea7d7ba549b6543272928dc3d4768261e9 @cliftonc committed
View
17 lib/core/Module.js
@@ -28,7 +28,9 @@ function eventRouteModules(req, res, next) {
res.routeMatched = false;
// Store our callback here
- req.routeComplete = next;
+ req.routeComplete = function(res) {
+ if(!res.finished) next();
+ };
// Route 'first' modules that fire before all others
// These first modules can stop the routing of all others
@@ -290,19 +292,20 @@ function doResponse(req, res, next) {
// Something went wrong at the layout, cannot use layout to render.
res.statusCode = 500;
- res.end("<html><h2>A fatal error occurred!</h2>" + "<p>" + (err.xMessage ? err.xMessage : err.message) + "</p>" + "<pre>" + err.stack + "</pre></html>");
- req.routeComplete();
+ res.send("<html><h2>A fatal error occurred!</h2>" + "<p>" + (err.xMessage ? err.xMessage : err.message) + "</p>" + "<pre>" + err.stack + "</pre></html>");
+ req.routeComplete(res);
} else {
res.setHeader('Content-Type', 'text/html');
// Who am I?
res.setHeader('X-Powered-By', 'Calipso');
+
// render
- res.end(content, 'utf-8');
+ res.send(content);
// Callback
- req.routeComplete();
+ req.routeComplete(res);
}
@@ -311,9 +314,7 @@ function doResponse(req, res, next) {
} else {
// Otherwise, provided we haven't already issued a redirect, then pass back to Express
- if(!res._headerSent) {
- req.routeComplete();
- }
+ req.routeComplete(res);
}
View
16 lib/core/Themes.js
@@ -102,11 +102,7 @@ module.exports.Theme = function(theme, next) {
},
render: function(req, res, next) {
- var cache = this.cache;
- var theme = this;
-
- // Scan through each layout
- var layout = res.layout ? res.layout : "default";
+ var cache = this.cache, theme = this, layout = res.layout ? res.layout : "default", content, themeOptions, err;
calipso.silly("Using layout " + layout);
@@ -128,15 +124,17 @@ module.exports.Theme = function(theme, next) {
}
// Now, process the layout template itself
- var themeOptions = createOptions(req, res, res.bufferedOutput);
+ themeOptions = createOptions(req, res, res.bufferedOutput);
try {
- var content = theme.cache[layout].template.call({}, themeOptions);
- next(null, content);
+ content = theme.cache[layout].template.call({}, themeOptions);
} catch (ex) {
- next(ex, null);
+ err = ex;
}
+ return next(err, content);
+
+
});
},
View
5 modules/core/admin/admin.js
@@ -324,7 +324,6 @@ function installMongoTest(req, res, template, block, next) {
if (calipso.config.get('installed')) {
res.format = "json";
res.end(JSON.stringify({status:"Invalid Request"}),"UTF-8");
- return next();
}
calipso.form.process(req,function(form) {
@@ -342,14 +341,12 @@ function installMongoTest(req, res, template, block, next) {
}
res.format = "json";
res.end(JSON.stringify(output),"UTF-8");
- next();
});
} else {
output.status = "FAILED";
output.message= "You need to provide a valid database uri, in the format described.";
res.format = "json";
res.end(JSON.stringify(output),"UTF-8");
- next();
}
});
@@ -402,7 +399,6 @@ function installUserTest(req, res, template, block, next) {
if (calipso.config.get('installed')) {
res.format = "json";
res.end(JSON.stringify({status:"Invalid Request"}),"UTF-8");
- return next();
}
@@ -438,7 +434,6 @@ function installUserTest(req, res, template, block, next) {
}
res.format = "json";
res.end(JSON.stringify(output),"UTF-8");
- next();
});
View
2 test/fixtures/modules/core/module_a/templates/test.html
@@ -0,0 +1,2 @@
+<h1>Test</h1>
+<%- hello %>
View
7 test/helpers/calipsoHelper.js
@@ -125,6 +125,13 @@ function CreateResponse() {
res.redirectQueue = [];
res.redirect = function (url) {
res.redirectQueue.push(url);
+ res.finished = false;
+ }
+ res.end = function(content, type) {
+ res.body = content;
+ }
+ res.send = function(content) {
+ res.body = content;
}
return res;
}
View
17 test/lib.calipso.js
@@ -39,7 +39,7 @@ describe('Calipso', function(){
res.outputStack = [];
// Over ride the res.end and increment our counter
- res.end = function(content) {
+ res.send = function(content) {
response++;
}
@@ -62,7 +62,7 @@ describe('Calipso', function(){
res.outputStack = [];
// Over ride the res.end and increment our counter
- res.end = function(content) {
+ res.send = function(content) {
response++;
}
@@ -87,15 +87,15 @@ describe('Calipso', function(){
res.outputStack = [];
// Over ride the res.end and increment our counter
- res.end = function(content) {
+ res.send = function(content) {
responseContent = content;
response++;
}
- routeFn(req, res, function(err) {
+ routeFn(req, res, function(err) {
response.should.equal(1);
res.outputStack.should.eql(['module_first','module_a','module_last']);
- responseContent.should.include('Test Template: world');
+ responseContent.should.include('world');
done();
})
@@ -111,12 +111,7 @@ describe('Calipso', function(){
req.url = '/secured';
res.outputStack = [];
- // Over ride the res.end and increment our counter
- res.end = function(content) {
- response++;
- }
-
- routeFn(req, res, function(err) {
+ routeFn(req, res, function(err) {
res.outputStack.should.eql(['module_first','module_last']);
req.flashMsgs[0].type.should.equal('error');
res.redirectQueue.length.should.equal(1);

0 comments on commit 7edc0ee

Please sign in to comment.
Something went wrong with that request. Please try again.