Permalink
Browse files

[minor] Log an error when the static directory doesn't exist. Fixes #16

  • Loading branch information...
1 parent 64e6169 commit 54dc6b3c8af8709635ac4e5301e91968055a764b @3rd-Eden committed Mar 13, 2013
Showing with 22 additions and 8 deletions.
  1. +7 −7 bin/versions
  2. +10 −1 index.js
  3. +5 −0 test/middleware.test.js
View
@@ -2,10 +2,10 @@
var version = require('../package.json').version;
-require('../').clone().path('../').lifetime('10 hours').listen(8081, function (err) {
- if (!err) {
- return console.log('[versions] Started versions/'+ version, 'on port 8081');
- }
-
- return console.error('[versions] Failed to start Versions');
-});
+require('../')
+ .path('../')
+ .lifetime('10 hours')
+ .listen(8081, function (err) {
+ if (err) return this.logger.error('[versions] Failed to start Versions');
+ this.logger.log('[versions] Started versions/'+ version, 'on port 8081');
+ });
View
@@ -228,7 +228,16 @@ Versions.prototype.listen = function listen(port, callback) {
// Only add static server support if it a `directory` was specified in the
// configuration.
if (this.get('directory')) {
- this.layer('static', this.get('static'), { maxAge: this.get('max age') });
+ // Check if the directory exists, we can just lazy require the fs module
+ // here as the listen call is done during the boot strapping of the server.
+ if (require('fs').existsSync(this.get('static'))) {
+ this.layer('static', this.get('static'), { maxAge: this.get('max age') });
+ } else {
+ this.logger.error(
+ '[versions] The %s does not exists, local file serving is disabled'
+ , this.get('static')
+ );
+ }
}
// Routing should only be enabled with an `auth` configuration.
View
@@ -37,6 +37,11 @@ describe('version.layer() integration', function () {
});
});
+ describe('.layer(static)', function () {
+ it('logs an error when the supplied static directory does not exist');
+ it('serves local hosted files');
+ });
+
describe('.layer(initalize)', function () {
it('sets the proper headers', function (done) {
versions.app.request()

0 comments on commit 54dc6b3

Please sign in to comment.