From 659af29adbd041fbbbaf041ead53266210a61f4e Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 27 Oct 2010 15:31:10 -0700 Subject: jsdoc parser + generator + viewer + scenario runner - parse jsdocs from source code - generate prerendered (markdown + mustache) partials - generate json - generate scenario runner for examples in docs - basic angular doc viewer --- lib/nodeserver/server.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'lib/nodeserver/server.js') diff --git a/lib/nodeserver/server.js b/lib/nodeserver/server.js index f91f6afa..bcaed299 100644 --- a/lib/nodeserver/server.js +++ b/lib/nodeserver/server.js @@ -84,12 +84,14 @@ StaticServlet.MimeMap = { StaticServlet.prototype.handleRequest = function(req, res) { var self = this; - var path = ('./' + req.url.pathname).replace('//','/'); + var path = ('./' + req.url.pathname).replace('//','/').replace(/%(..)/, function(match, hex){ + return String.fromCharCode(parseInt(hex, 16)); + }); var parts = path.split('/'); if (parts[parts.length-1].charAt(0) === '.') return self.sendForbidden_(req, res, path); fs.stat(path, function(err, stat) { - if (err) + if (err) return self.sendMissing_(req, res, path); if (stat.isDirectory()) return self.sendDirectory_(req, res, path); @@ -118,8 +120,8 @@ StaticServlet.prototype.sendMissing_ = function(req, res, path) { res.write('404 Not Found\n'); res.write('

Not Found

'); res.write( - '

The requested URL ' + - escapeHtml(path) + + '

The requested URL ' + + escapeHtml(path) + ' was not found on this server.

' ); res.end(); @@ -135,7 +137,7 @@ StaticServlet.prototype.sendForbidden_ = function(req, res, path) { res.write('403 Forbidden\n'); res.write('

Forbidden

'); res.write( - '

You do not have permission to access ' + + '

You do not have permission to access ' + escapeHtml(path) + ' on this server.

' ); res.end(); @@ -151,8 +153,8 @@ StaticServlet.prototype.sendRedirect_ = function(req, res, redirectUrl) { res.write('301 Moved Permanently\n'); res.write('

Moved Permanently

'); res.write( - '

The document has moved here.

' ); res.end(); @@ -187,7 +189,7 @@ StaticServlet.prototype.sendDirectory_ = function(req, res, path) { return self.sendRedirect_(req, res, redirectUrl); } fs.readdir(path, function(err, files) { - if (err) + if (err) return self.sendError_(req, res, error); if (!files.length) @@ -235,5 +237,5 @@ StaticServlet.prototype.writeDirectoryIndex_ = function(req, res, path, files) { res.end(); }; -// Must be last, +// Must be last, main(process.argv); -- cgit v1.2.3