Skip to content
Browse files

[fix] Will now handle case properly where no 404.html exists

  • Loading branch information...
1 parent ab9cb09 commit d32ad4b2ef77e26164c98cfe93e9f93c413f4fbb @jfhbrook jfhbrook committed
Showing with 10 additions and 1 deletion.
  1. +10 −1 lib/http-server.js
View
11 lib/http-server.js
@@ -9,6 +9,7 @@
var colors = require('colors'),
argv = require('optimist').argv,
static = require('node-static'),
+ fs = require("fs");
http = require('http');
var HTTPServer = exports.HTTPServer = function (options) {
@@ -39,7 +40,15 @@ HTTPServer.prototype.start = function () {
self.log('['.grey+'served'.yellow+'] '.grey + request.url);
return self.file.serve(request, response, function (err, result) {
if (err && err.status == 404) {
- self.file.serveFile("/404.html", err.status, {}, request, response);
+ // Catch case where there is no 404 file
+ fs.stat(self.root + "/404.html", function (err, stat) {
+ if (!err && stat.isFile()) {
+ self.file.serveFile("/404.html", err.status, {}, request, response);
+ } else {
+ response.writeHead(404);
+ response.end();
+ }
+ });
}
});
});

0 comments on commit d32ad4b

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