Skip to content

Commit

Permalink
Stock 404 response
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBeale committed May 5, 2015
1 parent 8d653fe commit 4f04f7e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,26 @@ module.exports = function (rootDirectory, logger, indexDocument, errorDocument)

if (indexDocument)
{
return notFoundResponse(req, res);
}
else
{
var template = templateBuilder.buildKeyNotFound(keyName);
return buildXmlResponse(res, 404, template);
}
};


var notFoundResponse = function(req, res)
{
var ErrorDoc = '<!DOCTYPE html>\n<html><head><title>404 - Resource Not Found</title></head><body><h1>404 - Resource Not Found</h1></body></html>';

return buildResponse(req, res, 404, {
md4: '',
modifiedDate: new Date(),
contentType: 'text/html',
customMetaData: [],
size: ErrorDoc.length
}, ErrorDoc);
}
else
{
var template = templateBuilder.buildKeyNotFound(keyName);
return buildXmlResponse(res, 404, template);
}
};

/**
Expand Down
21 changes: 21 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,4 +673,25 @@ describe('S3rver Tests with Static Web Hosting', function () {
});
});


it('should get a 404 error page', function (done) {
request('http://localhost:5694/site/page/not-exists', function (error, response, body) {
if (error)
{
return done(error);
}

if (response.statusCode !== 404) {
return done(new Error('Invalid status: ' + response.statusCode));
}

if (response.headers['content-type'] !== 'text/html; charset=utf-8')
{
return done(new Error('Invalid ContentType: ' + response.headers['content-type']));
}

done();
});
});

});

0 comments on commit 4f04f7e

Please sign in to comment.