Permalink
Browse files

[app] quick refactoring

  • Loading branch information...
1 parent 75dd5dc commit 9144ddfba0bbc91feb6542b78e10b0bb8f0ff175 @jankeromnes jankeromnes committed Jan 3, 2013
Showing with 32 additions and 24 deletions.
  1. +26 −24 app.js
  2. +6 −0 lib/fsapi.js
View
50 app.js
@@ -1,37 +1,41 @@
-/* Run this with node to start your tree server.
+/* Run this with node to start your file tree server.
* Copyright © 2011 Thaddee Tyl, Jan Keromnes. All rights reserved.
* The following code is covered by the GPLv2 license. */
-// Please look for documentation in `./Server.md`
+// IMPORT MODULES
+//
+
+var Camp = require('camp'),
+ nodepath = require('path'),
+ driver = require('./lib/driver'),
+ fsapi = require('./lib/fsapi'),
+ irc = require('./lib/irc'),
+ plug = require('./lib/plug'),
+ profiler = require('./lib/profiler');
-// SERVER CONFIG
+
+// SERVER SETUP
//
-// Import modules
-var Camp = require('camp'),
- camp = Camp.start({
- port: +process.argv[2],
- secure: process.argv[3] === 'yes',
- debug: +process.argv[4],
- key: 'https.key',
- cert: 'https.crt',
- ca: ['https.ca'],
- }),
- driver = require('./lib/driver'),
- fsapi = require('./lib/fsapi'),
- irc = require('./lib/irc'),
- plug = require('./lib/plug'),
- profiler = require('./lib/profiler'),
- nodepath = require('path');
+// Start the server with command line options
+var camp = Camp.start({
+ port: +process.argv[2],
+ secure: process.argv[3] === 'yes',
+ debug: +process.argv[4],
+ key: 'https.key',
+ cert: 'https.crt',
+ ca: ['https.ca'],
+});
// Socket.io: silence will fall!
camp.io.configure('development', function () {
camp.io.set('log level', 0);
camp.io.set('browser client minification', true);
-// camp.io.set('browser client gzip', true); // FIXME broken since v0.8.0
+//camp.io.set('browser client gzip', true); // FIXME broken in Socket.io
});
+// Custom templating filter
Camp.Plate.parsers['script'] = function (text) {
return text.replace(/</g, '\\u003c');
};
@@ -43,20 +47,18 @@ plug.main(camp);
// ROUTING
//
-camp.route(/\/(.*)/, plug.resolve); // Redirect all URLs to corresponding plug.
+// Redirect all requests to a templated plug.
+camp.route(/\/(.*)/, plug.resolve);
// Profiler API.
camp.ajax.on('profiler', function (query, end) { end(profiler.run(query)); });
-
// File System API.
camp.ajax.on('fs', fsapi.fs);
-
// Metadata API.
camp.ajax.on('meta-save', fsapi.meta);
-
// IRC API.
camp.ajax.on('join', irc.join);
camp.ajax.on('say', irc.say);
View
@@ -7,6 +7,9 @@ var fs = require('./fs'),
nodepath = require('path');
+// FILE SYSTEM API
+//
+
// read(1) - Read information about a file or folder, represented by a `path`.
// If `depth` is non-negative, read folder subfiles recursively.
// If it is zero, read file content.
@@ -97,10 +100,12 @@ function fsOperation(query, end) {
// It must also have a `path` field, which is a String.
if (query.op == null) {
end({err: 'An invalid request was sent to the file system.'});
+ return;
}
if (query.path == null) {
end({err: 'A request was sent to the file system, ' +
'but did not specify the path.'});
+ return;
}
var data = {};
switch (query.op) {
@@ -115,6 +120,7 @@ function fsOperation(query, end) {
break;
default:
end({err: 'Unknown file system operation ' + query.op + '.'});
+ break;
}
}

0 comments on commit 9144ddf

Please sign in to comment.