Skip to content

Commit d32ad4b

Browse files
committed
[fix] Will now handle case properly where no 404.html exists
1 parent ab9cb09 commit d32ad4b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/http-server.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
var colors = require('colors'),
1010
argv = require('optimist').argv,
1111
static = require('node-static'),
12+
fs = require("fs");
1213
http = require('http');
1314

1415
var HTTPServer = exports.HTTPServer = function (options) {
@@ -39,7 +40,15 @@ HTTPServer.prototype.start = function () {
3940
self.log('['.grey+'served'.yellow+'] '.grey + request.url);
4041
return self.file.serve(request, response, function (err, result) {
4142
if (err && err.status == 404) {
42-
self.file.serveFile("/404.html", err.status, {}, request, response);
43+
// Catch case where there is no 404 file
44+
fs.stat(self.root + "/404.html", function (err, stat) {
45+
if (!err && stat.isFile()) {
46+
self.file.serveFile("/404.html", err.status, {}, request, response);
47+
} else {
48+
response.writeHead(404);
49+
response.end();
50+
}
51+
});
4352
}
4453
});
4554
});

0 commit comments

Comments
 (0)