Skip to content

Commit

Permalink
fixed error handling bugs related to public files and added some bett…
Browse files Browse the repository at this point in the history
…er default error styles
  • Loading branch information
shanebo committed Jul 2, 2013
1 parent 17da336 commit 46c1c4f
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 30 deletions.
12 changes: 6 additions & 6 deletions lib/calvin/middleware/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ var Assets = function(app){
console.log('--> Initializing Cache middleware...');
this.app = app;

this.defaultAssets();

this.app.cache.forEach(function(dir){
this.cacheDirectory(dir);
}.bind(this));

this.combineAssets();
this.defaultErrors();
};


Assets.prototype = {

defaultErrors: function(){
defaultAssets: function(){
['403', '404', '500', 'error'].forEach(function(status){
if (!this.app.cache.hasOwnProperty('/views/'+ status + '.html')) {
this.storeFile(__dirname + '/../public/'+ status +'.html', '/views/'+ status +'.html');
}
this.storeFile(__dirname + '/../public/'+ status +'.html', '/views/calvin/'+ status +'.html');
}.bind(this));

this.storeFile(__dirname + '/../public/errors.css', '/public/errors.css');
this.storeFile(__dirname + '/../public/errors.css', '/public/calvin/errors.css');
this.storeFile(__dirname + '/../public/favicon.ico', '/public/favicon.ico');
},

cacheDirectory: function(dir){
Expand Down
2 changes: 1 addition & 1 deletion lib/calvin/middleware/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Router.prototype = {
['403', '404', '500'].forEach(function(status){
this.get('/' + status, function(request, response){
response.writeHead(status, { 'Content-Type': 'text/html' });
response.end(response.partial(status + '.html', { status: status }));
response.end(response.partial('calvin/' + status + '.html', { status: status }));
});
}.bind(this));
},
Expand Down
3 changes: 2 additions & 1 deletion lib/calvin/public/403.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<html>
<head>
<title>{status}</title>
<link rel="stylesheet" type="text/css" href="/errors.css" media="screen, print">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="/calvin/errors.css" media="screen, print">
</head>

<body class="public">
Expand Down
7 changes: 4 additions & 3 deletions lib/calvin/public/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
<html>
<head>
<title>{status}</title>
<link rel="stylesheet" type="text/css" href="/errors.css" media="screen, print">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="/calvin/errors.css" media="screen, print">
</head>

<body class="public">
<div id="error">
<h1>Oops.</h1>
<p>Path could not be found.<br /><a href="/">&#x2190; Go to the home page</a></p>
<h1>Path Not Found</h1>
<p>The path you entered or visited doesn't exist.<br /><a href="/">&#x2190; Try going to the home page</a></p>
</div>
</body>
</html>
3 changes: 2 additions & 1 deletion lib/calvin/public/500.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<html>
<head>
<title>{status}</title>
<link rel="stylesheet" type="text/css" href="/errors.css" media="screen, print">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="/calvin/errors.css" media="screen, print">
</head>

<body class="public">
Expand Down
3 changes: 2 additions & 1 deletion lib/calvin/public/error.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<html>
<head>
<title>{error}</title>
<link rel="stylesheet" type="text/css" href="/errors.css" media="screen, print">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="/calvin/errors.css" media="screen, print">
</head>

<body>
Expand Down
32 changes: 17 additions & 15 deletions lib/calvin/public/errors.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
* {
margin: 0px;
padding: 0px;
}

body {
background: #262626;
font: normal 1em/1.5em "Helvetica Neue", Helvetica, Arial, Geneva, sans-serif;
color: #262626;
background: #f7f7f7;
text-align: left;
font: normal 14px/1.6 "Helvetica Neue", Helvetica, Arial, Geneva, sans-serif;
}

#error {
margin: 30px;
}

h1,
Expand All @@ -27,12 +21,20 @@ h1 em {
background: #ff6;
}


body.public {
text-align: center;
#error {
margin: 30px;
}

.public #error {
text-align: center;
width: 610px;
margin: 30px auto;
}
margin: 54px auto;
background: #fff;
padding: 30px;
font: normal 1em/1.5em "Helvetica Neue", Helvetica, Arial, Geneva, sans-serif;
color: #262626;
box-shadow: 0px 1px 3px rgba(0,0,0,.2);
-moz-box-shadow: 0px 1px 3px rgba(0,0,0,.2);
-webkit-box-shadow: 0px 1px 3px rgba(0,0,0,.2);
border-radius: 3px;
}
4 changes: 2 additions & 2 deletions lib/calvin/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var Response = {
},

error: function(err, status, options){
if (process.env.NODE_ENV === 'production') {
if (options.environment === 'production') {
options.routes['get']['/' + status].fn(this.request, this);
} else {
status = ['403','404','500'].contains(status) ? status : '500';
Expand All @@ -37,7 +37,7 @@ var Response = {
if (errors.hasOwnProperty(status)) view.error.message += (' ' + errors[status]);

this.writeHead(status, { 'Content-Type': 'text/html' });
this.end(this.partial('error.html', view));
this.end(this.partial('calvin/error.html', view));
}
},

Expand Down

0 comments on commit 46c1c4f

Please sign in to comment.