Browse files

switch response to html, linkify directory

  • Loading branch information...
1 parent ecdd7bc commit 4ab17c8666a31d43a8dbfd201cf76b1e06b0f741 @angus-c committed Oct 30, 2011
Showing with 9 additions and 6 deletions.
  1. +9 −6 src/server.js
View
15 src/server.js
@@ -21,39 +21,42 @@ http.createServer(function (request, response) {
}
//...or copy
filename = pathname;
- respNew("\nasked to copy", pathname, "...");
+ respNew("<span>asked to copy", pathname, "...</span>");
fs.readFile(fromPath + pathname, copyData);
})(unescape(url.parse(request.url).pathname));
/********************************************/
function copyData(err, data) {
err || fs.writeFile(toPath + filename, data);
respAdd(err || ["copied", filename, "to", toPath].join(" "));
+ respAdd("<a href='/'>copy another?</a>");
serveResponse(err);
}
function listDirectory(err, data) {
fs.readdir(fromPath, function(err, files) {
- respNew("\nchoose a file to copy from", fromPath, "...\n");
- respAdd(files.join('\n'));
+ respNew("<span>Copy from", "<code>" + fromPath + "</code><br>to<code>" + toPath + "</code><br>");
+ respAdd(files.map(function(e) {
+ return ["<a href='", "/", e, "'>", e, "</a>"].join('');
+ }).join('<br>'));
serveResponse(err);
})
}
function serveResponse(err) {
response.writeHead(err ? 400 : 200, {
- "Content-Type": "text/plain"
+ "Content-Type": "text/html"
});
response.write(respContent);
response.end();
}
function respAdd(/*arguments*/) {
- respContent += ("\n" + [].slice.call(arguments).join(" "));
+ respContent += ("<br>" + [].slice.call(arguments).join(" "));
}
function respNew(/*arguments*/) {
- respContent = ("\n" + [].slice.call(arguments).join(" "));
+ respContent = ("<br>" + [].slice.call(arguments).join(" "));
}
}).listen(port);

0 comments on commit 4ab17c8

Please sign in to comment.