Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 4 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
Showing with 281 additions and 26 deletions.
  1. 0 README → README.md
  2. +21 −2 app.js
  3. +21 −21 htdocs/js/mikevalstar.js
  4. +92 −0 lib/ErrorHandler.js
  5. +85 −0 log/error_log
  6. +3 −3 package.json
  7. +3 −0 views/404.jade
  8. +56 −0 views/error.jade
View
0 README → README.md
File renamed without changes.
View
23 app.js
@@ -14,12 +14,16 @@ app.configure(function(){
app.use(express.static(__dirname + '/htdocs'));
});
+var error = require('./lib/ErrorHandler');
+
app.configure('development', function(){
- app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
+ //app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
+ app.use(error({ showMessage: true, dumpExceptions: true, showStack: true, logErrors: __dirname + '/log/error_log' }));
});
app.configure('production', function(){
- app.use(express.errorHandler());
+ //app.use(express.errorHandler());
+ app.use(error());
});
// Internal Page Handlers
@@ -27,6 +31,21 @@ var static_pages = require('./lib/StaticPages');
var sp = new static_pages();
sp.initPages(app);
+// 404 Page
+app.use(function(req, res, next){
+ res.writeHead(404);
+ res.render('404.jade', {title: "404 - Page Not Found", showFullNav: false, status: 404, url: req.url });
+});
+
+// Example error pages
+app.get('/ErrorExample', function(req, res, next){
+ next(new Error('keyboard cat!')); // trigger an error
+});
+
+app.get('/ErrorExample2', function(req, res){
+ res.render('404.jade'); // force an error.. we did not set the title
+});
+
app.listen(3000);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
View
42 htdocs/js/mikevalstar.js
@@ -1,7 +1,7 @@
-/*
- Welcome to my Javascript
+/*
+ Welcome to my Javascript
- Please vist mikevalstar.com for an explination
+ Please vist mikevalstar.com for an explination
about how some of the below is done.
*/
@@ -18,17 +18,17 @@ MV.nav = {
isExpanded: function(){
return $('.ex').length > 0;
}
-
+
, transform: function(quick){
if(!MV.nav.isExpanded()) return; // already shrunk
-
- if(quick){
+
+ if(quick){
$('#Nav').removeClass('ex');
$("#NTwitter div li:not(.tweet_first)").remove();
$('#C').removeClass('hide');
return;
}
-
+
$('#Nav>ul>li').animate({ height: '50', paddingTop: '25', paddingBottom: '25' }, 700, function(){
$('#Nav').removeClass('ex');
$("#NTwitter div li:not(.tweet_first)").remove();
@@ -45,30 +45,30 @@ MV.content = {
_gaq.push(['_trackPageview']);
return; // nothing to do
}
-
+
var url = (hash[0] == '#') ? hash.substring(2): hash;
-
+
MV.nav.transform(transform); // transform the navigation if needed
-
+
$('#CC').html('Loading Content...');
-
+
var callback = function(responseText, textStatus, XMLHttpRequest){
if($('#disqus_thread').length == 1)
MV.content.loadDisqus();
-
+
MV.content.loadGist();
$(document).attr('title', $(responseText).filter('title').text());
-
+
if(fn) fn();
-
+
// track the page view
if(typeof _gaq !== 'undefined')
_gaq.push(['_trackPageview', url]);
}
-
+
$('#C').load(url + ' #CC', callback);
}
-
+
, loadDisqus: function(){
disqus_identifier = $('#disqus_identity').html();
disqus_url = $('#disqus_permalink a').attr('href');
@@ -76,9 +76,9 @@ MV.content = {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
-
+
}
-
+
, loadGist: function(){
var gists = $('.gistC');
$.each(gists, function(){
@@ -92,7 +92,7 @@ $(function(){
// Initialize page
$("a").live("click", function(event){
var href = $(this).attr("href");
- if(href[0] == "/"
+ if(href[0] == "/"
&& href.substring(href.length - 4) != '.png'
&& href.substring(href.length - 4) != '.jpg'
&& href.substring(href.length - 5) != '.jpeg'
@@ -110,10 +110,10 @@ $(function(){
username: "mikevalstar",
join_text: "auto",
avatar_size: 48,
- count: $('#Nav.ex').length || (location.hash && location.hash != '') == 0 ? 1 : 6,
+ count: $('#Nav.ex').length == 0 || (location.hash && location.hash != '') ? 1 : 6,
loading_text: "loading tweets..."
});
-
+
// initialize the hash lookup
$(window).hashchange( function(){
MV.content.load( location.hash );
View
92 lib/ErrorHandler.js
@@ -0,0 +1,92 @@
+/**
+ * Modified from the Connect project: https://github.com/senchalabs/connect/blob/master/lib/middleware/errorHandler.js
+ *
+ * Flexible error handler, providing (_optional_) stack traces and logging
+ * and error message responses for requests accepting text, html, or json.
+ *
+ * Options:
+ *
+ * - `showStack` respond with both the error message and stack trace. Defaults to `false`
+ * - `showMessage`, respond with the exception message only. Defaults to `false`
+ * - `dumpExceptions`, dump exceptions to stderr (without terminating the process). Defaults to `false`
+ * - `logErrors`, will dump a log entry and stack trace into the gievn file. Defaults to `false`
+ *
+ * Text:
+ * By default, and when _text/plain_ is accepted a simple stack trace
+ * or error message will be returned.
+ *
+ * JSON:
+ * When _application/json_ is accepted, connect will respond with
+ * an object in the form of `{ "error": error }`.
+ *
+ * HTML:
+ * When accepted connect will output a nice html stack trace.
+ *
+ * @param {Object} options
+ * @return {Function}
+ * @api public
+ */
+
+var fs = require('fs');
+
+exports = module.exports = function errorHandler(options){
+ options = options || {};
+ // defaults
+ var showStack = options.showStack
+ , showMessage = options.showMessage
+ , dumpExceptions = options.dumpExceptions
+ , logErrors = options.logErrors
+ , logErrorsStream = false;
+
+ if(options.logErrors)
+ logErrorsStream = fs.createWriteStream(logErrors, {'flags': 'a', encoding: 'utf-8', mode: 0666});
+
+ return function errorHandler(err, req, res, next){
+ res.statusCode = 500;
+
+ if(dumpExceptions) console.error(err.stack);
+
+ if(logErrors){
+ var now = new Date();
+ logErrorsStream.write(now.toJSON() + ' - Error Happened: \n' + err.stack + "\n");
+ }
+
+ var accept = req.headers.accept || '';
+ if(showStack) {
+ // html
+ if (~accept.indexOf('html')) {
+ res.render('error.jade', {
+ layout: false
+ , stack: err.stack || ''
+ , error: err.toString()
+ });
+ // json
+ } else if (~accept.indexOf('json')) {
+ var json = JSON.stringify({ error: err });
+ res.setHeader('Content-Type', 'application/json');
+ res.end(json);
+ // plain text
+ } else {
+ res.writeHead(500, { 'Content-Type': 'text/plain' });
+ res.end(err.stack);
+ }
+ }else{
+ // public error page render
+ // html
+ if (~accept.indexOf('html')) {
+ res.render('error.jade', {
+ layout: false
+ });
+ // json
+ } else if (~accept.indexOf('json')) {
+ var json = JSON.stringify({ error: "There was a server error generating the content." });
+ res.setHeader('Content-Type', 'application/json');
+ res.end(json);
+ // plain text
+ } else {
+ res.writeHead(500, { 'Content-Type': 'text/plain' });
+ res.end("500 - Server Error");
+ }
+ }
+ };
+};
View
85 log/error_log
@@ -0,0 +1,85 @@
+2011-11-17T19:08:47.450Z - Error Happened:
+Error: keyboard cat!
+ at /Users/mikevalstar/Dropbox/Public/mv_app/app.js:44:8
+ at callbacks (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:272:11)
+ at param (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:246:11)
+ at pass (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:253:5)
+ at Router._dispatch (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:280:4)
+ at Object.handle (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:45:10)
+ at next (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/node_modules/connect/lib/http.js:201:15)
+ at Object.methodOverride [as handle] (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/node_modules/connect/lib/middleware/methodOverride.js:35:5)
+ at next (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/node_modules/connect/lib/http.js:201:15)
+ at Object.bodyParser [as handle] (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/node_modules/connect/lib/middleware/bodyParser.js:59:61)2011-11-17T19:08:58.254Z - Error Happened:
+Error: keyboard cat!
+ at /Users/mikevalstar/Dropbox/Public/mv_app/app.js:44:8
+ at callbacks (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:272:11)
+ at param (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:246:11)
+ at pass (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:253:5)
+ at Router._dispatch (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:280:4)
+ at Object.handle (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:45:10)
+ at next (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/node_modules/connect/lib/http.js:201:15)
+ at Object.methodOverride [as handle] (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/node_modules/connect/lib/middleware/methodOverride.js:35:5)
+ at next (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/node_modules/connect/lib/http.js:201:15)
+ at Object.bodyParser [as handle] (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/node_modules/connect/lib/middleware/bodyParser.js:59:61)2011-11-17T19:09:09.524Z - Error Happened:
+Error: keyboard cat!
+ at /Users/mikevalstar/Dropbox/Public/mv_app/app.js:44:8
+ at callbacks (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:272:11)
+ at param (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:246:11)
+ at pass (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:253:5)
+ at Router._dispatch (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:280:4)
+ at Object.handle (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:45:10)
+ at next (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/node_modules/connect/lib/http.js:201:15)
+ at Object.methodOverride [as handle] (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/node_modules/connect/lib/middleware/methodOverride.js:35:5)
+ at next (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/node_modules/connect/lib/http.js:201:15)
+ at Object.bodyParser [as handle] (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/node_modules/connect/lib/middleware/bodyParser.js:59:61)2011-12-09T18:33:18.956Z - Error Happened:
+ReferenceError: /Users/mikevalstar/Dropbox/Public/mv_app/views/layout.jade:4
+ 2| html(lang="en")
+ 3| head
+ > 4| title #{title} - Mike Valstar - Programming & Web Development
+ 5| link(rel='stylesheet', href='/css/css.css')
+ 6|
+ 7| script(src='http://code.jquery.com/jquery-1.7.min.js', type='text/javascript')
+
+title is not defined
+ at eval at <anonymous> (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/jade/lib/jade.js:165:3)
+ at Object.<anonymous> (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/jade/lib/jade.js:166:12)
+ at ServerResponse._render (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/view.js:422:21)
+ at ServerResponse.render (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/view.js:315:17)
+ at ServerResponse._render (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/view.js:429:10)
+ at ServerResponse.render (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/view.js:315:17)
+ at /Users/mikevalstar/Dropbox/Public/mv_app/app.js:36:7
+ at callbacks (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:272:11)
+ at param (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:246:11)
+ at pass (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:253:5)
+2011-12-09T18:34:11.142Z - Error Happened:
+Error: keyboard cat!
+ at /Users/mikevalstar/Dropbox/Public/mv_app/app.js:44:8
+ at callbacks (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:272:11)
+ at param (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:246:11)
+ at pass (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:253:5)
+ at Router._dispatch (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:280:4)
+ at Object.handle (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:45:10)
+ at next (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/node_modules/connect/lib/http.js:203:15)
+ at Object.methodOverride [as handle] (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/node_modules/connect/lib/middleware/methodOverride.js:35:5)
+ at next (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/node_modules/connect/lib/http.js:203:15)
+ at Object.bodyParser [as handle] (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/node_modules/connect/lib/middleware/bodyParser.js:85:61)
+2011-12-09T18:36:52.500Z - Error Happened:
+ReferenceError: /Users/mikevalstar/Dropbox/Public/mv_app/views/layout.jade:4
+ 2| html(lang="en")
+ 3| head
+ > 4| title #{title} - Mike Valstar - Programming &amp; Web Development
+ 5| link(rel='stylesheet', href='/css/css.css')
+ 6|
+ 7| script(src='http://code.jquery.com/jquery-1.7.min.js', type='text/javascript')
+
+title is not defined
+ at eval at <anonymous> (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/jade/lib/jade.js:165:3)
+ at Object.<anonymous> (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/jade/lib/jade.js:166:12)
+ at ServerResponse._render (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/view.js:422:21)
+ at ServerResponse.render (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/view.js:315:17)
+ at ServerResponse._render (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/view.js:429:10)
+ at ServerResponse.render (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/view.js:315:17)
+ at /Users/mikevalstar/Dropbox/Public/mv_app/app.js:36:7
+ at callbacks (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:272:11)
+ at param (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:246:11)
+ at pass (/Users/mikevalstar/Dropbox/Public/mv_app/node_modules/express/lib/router/index.js:253:5)
View
6 package.json
@@ -1,9 +1,9 @@
{
- "name": "application-name"
- , "version": "0.0.1"
+ "name": "mikevalstar.com website"
+ , "version": "0.0.2"
, "private": true
, "dependencies": {
- "express": "2.4.7"
+ "express": ">= 2.5.0"
, "jade": ">= 0.0.1"
, "markdown-js": ">= 0.0.1"
}
View
3 views/404.jade
@@ -0,0 +1,3 @@
+h2 404
+
+h3 Page Not Found
View
56 views/error.jade
@@ -0,0 +1,56 @@
+!!! 5
+html(lang="en")
+head
+ title Error - Mike Valstar - Programming &amp; Web Development
+ link(rel='stylesheet', href='/css/css.css')
+
+ script(src='http://code.jquery.com/jquery-1.7.min.js', type='text/javascript')
+ script(src='/js/jquery.tweet.js', type='text/javascript')
+ script(src='/js/jquery.ba-hashchange.min.js', type='text/javascript')
+ script(src='/js/script.min.js', type='text/javascript')
+ script(src='/js/mikevalstar.js', type='text/javascript')
+
+ //if lt IE 9
+ script(src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js")
+
+ script(type="text/javascript")
+ var _gaq = _gaq || [];
+ _gaq.push(['_setAccount', 'UA-1984894-13']);
+
+ (function() {
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+ })();
+
+body#mikevalstar
+ #O
+
+ #H
+ h1: a(href="http://mikevalstar.com/") Mike Valstar
+ #social
+ //- a(href="#"): img(src="/img/rss.png", alt="RSS")
+ a(href="https://github.com/mikevalstar"): img(src="/img/github.png", alt="Github")
+ a(href="https://plus.google.com/107235391839316017795"): img(src="/img/google-plus.png", alt="Google+")
+ a(href="http://twitter.com/#!/mikevalstar"): img(src="/img/twitter.png", alt="Twitter")
+
+ h2 Web Development, Programming, Random Thoughts
+
+ #Nav
+ ul
+ li#NBlog: a(href="/Blog") Blog
+ li#NProjects: a(href="/Projects") Projects
+ li#NAbout: a(href="/About") About
+ li#NTwitter: div Twitter Feed
+ div.clear
+
+ #C
+ #CC
+ h2 500 Error
+
+ - if(stack)
+ pre: code.stack!=stack
+ - else
+ There was an error rendering this page. Sorry for the inconvenience.
+
+ #F Mike Valstar &copy; 2011

No commit comments for this range

Something went wrong with that request. Please try again.