Skip to content

Commit

Permalink
- dr.js -n to run static site without JSON server (useful for testi…
Browse files Browse the repository at this point in the history
…ng UI error behavior)

- lots of UI changes:
  * twitter-like notification bar for errors
  * cosmetic changes to the tooltip bubbles in index.html
  * ajaxy progress animation while waiting for server
  * fixed a variable shadowing bug (status) that was causing tooltip bubbles to reload every time
  * try.html puts results in a formatted div instead of a textarea
  * try.html results are pretty-fied instead of just given as raw JSON
  • Loading branch information
David Herman authored and David Herman committed Aug 25, 2010
1 parent ba54b82 commit 816ffc3
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 1,192 deletions.
26 changes: 19 additions & 7 deletions bin/dr.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function usage(msg) {
sys.print("usage: " + path.basename(argv[1]) + " [options]\n");
sys.print(" -h/--help Print usage information\n");
sys.print(" -s/--static Directory containing static web content\n");
sys.print(" -n/--no-service Disable the JSON service");
sys.print(" -p/--port Server port to listen on\n");
if (msg) {
sys.print("\n" + msg + "\n");
Expand All @@ -66,12 +67,18 @@ function usage(msg) {
function parseOpts(argv, callback) {
var dir = null;
var port = 8080;
var service = true;

for (var i = 0; i < argv.length; i++) {
switch (argv[i]) {
case "--help":
case "-h":
callback(null, { help: true, dir: null, port: null });
callback(null, { help: true, dir: null, port: null, service: null });
break;

case "--no-service":
case "-n":
service = false;
break;

case "--port":
Expand All @@ -92,29 +99,34 @@ function parseOpts(argv, callback) {
case "-s":
i++;
if (i >= argv.length) {
callback("static source directory not specified");
callback("static source directory not specified", null);
return;
}
dir = argv[i];
break;
}
}

if (!service && !dir) {
callback("service disabled without static directory", null);
return;
}

if (!dir) {
callback(null, { help: false, dir: null, port: port });
callback(null, { help: false, dir: null, port: port, service: service });
return;
}

require('fs').stat(path.normalize(dir), function(err, stats) {
if (!stats || !stats.isDirectory())
callback("bad directory", null);
else
callback(null, { help: false, dir: dir, port: port });
callback(null, { help: false, dir: dir, port: port, service: service });
});
}

// construct a request handler for the entire web site
function makeSiteHandler(dir) {
function makeSiteHandler(dir, service) {
var mimeTypes = {
jpg: "image/jpeg",
png: "image/png",
Expand All @@ -126,7 +138,7 @@ function makeSiteHandler(dir) {
return function(req, resp) {
var query = url.parse(req.url).pathname;

if (query === '/analyze') {
if (service && query === '/analyze') {
servetypes.analyze(cwd, req, resp);
return;
}
Expand Down Expand Up @@ -178,7 +190,7 @@ parseOpts(argv.slice(2), function(err, opts) {
var handler;
if (opts.dir) {
sys.log("staging site from " + opts.dir);
handler = makeSiteHandler(opts.dir);
handler = makeSiteHandler(opts.dir, opts.service);
} else {
sys.log("running JSON service only");
handler = service;
Expand Down
Loading

0 comments on commit 816ffc3

Please sign in to comment.