Skip to content
Browse files

add stdout documentation

  • Loading branch information...
1 parent fe36c04 commit 764ea19ca2456b73f42287046682a7477e26ed2b @4z3 committed Aug 17, 2011
Showing with 24 additions and 12 deletions.
  1. +11 −0 README → README.md
  2. +7 −7 file.js
  3. +4 −4 proxy.js
  4. +2 −1 util.js
View
11 README → README.md
@@ -2,6 +2,7 @@ If affection lead a man to favor the less worthy in desert, let him do it,
without depraving or disabling the better deserver.
-- The Essays by Bacon, Sir Francis
+# Quick Start Guide
git clone https://github.com/4z3/deserver
node deserver &
@@ -11,3 +12,13 @@ without depraving or disabling the better deserver.
curl http://127.0.0.1:1337$f > $f # yay^_^
curl -X DELETE http://127.0.0.1:1337$f
+# STDOUT
+
+On startup the server annources itself using the following format:
+
+ "Deserving HTTP -> on %s port %u\n", hostname, port
+
+Each HTTP-request is reported using the following format:
+
+ "%s %s %u\n", method, url, statusCode
+
View
14 file.js
@@ -30,36 +30,36 @@ exports.create = function () {
methods.GET = function (req, res) {
if (!cache.hasOwnProperty(req.url))
- return end(res, 404);
+ return end(req, res, 404);
var file = cache[req.url];
- end(res, 200, { 'content-type': file.type }, file.content);
+ end(req, res, 200, { 'content-type': file.type }, file.content);
};
methods.PUT = function (req, res) {
if (cache.hasOwnProperty(req.url))
- return end(res, 405, { 'allow': 'GET, DELETE' });
+ return end(req, res, 405, { 'allow': 'GET, DELETE' });
return slurp(req, function (content) {
cache[req.url] = {
type: req.headers['content-type'],
content: content
};
- return end(res, 201);
+ return end(req, res, 201);
});
};
methods.DELETE = function (req, res) {
if (!cache.hasOwnProperty(req.url))
- return end(res, 404);
+ return end(req, res, 404);
delete cache[req.url];
- return end(res, 200);
+ return end(req, res, 200);
};
return function (req, res) {
if (!methods.hasOwnProperty(req.method))
- return end(res, 405, { 'allow': Object.keys(methods) });
+ return end(req, res, 405, { 'allow': Object.keys(methods) });
return methods[req.method](req, res);
};
View
8 proxy.js
@@ -42,7 +42,7 @@ exports.create = function () {
/^\/[^\/]+$/.test(req.url)) {
if (proxies.hasOwnProperty(req.url))
- return end(res, 405, { 'allow': 'GET, DELETE' });
+ return end(req, res, 405, { 'allow': 'GET, DELETE' });
return slurp(req, function (content) {
try {
@@ -52,7 +52,7 @@ exports.create = function () {
!(typeof proxy.baseURL === 'string'))
throw new Error('bad content');
} catch (exn) {
- return end(res, 400);
+ return end(req, res, 400);
};
proxies[req.url] = proxy;
return next(req, res);
@@ -89,10 +89,10 @@ exports.create = function () {
preq
.on('error', function (err) {
- end(res, 500);
+ end(req, res, 500);
})
.on('complete', function (p_content, p_res) {
- end(res, p_res.statusCode, p_res.headers, p_content);
+ end(req, res, p_res.statusCode, p_res.headers, p_content);
});
});
};
View
3 util.js
@@ -37,7 +37,7 @@ exports.slurp = (function () {
};
})();
-exports.end = function (res, statusCode, headers, content) {
+exports.end = function (req, res, statusCode, headers, content) {
var myheaders = {
'Content-Length': content && content.length || 0
};
@@ -48,4 +48,5 @@ exports.end = function (res, statusCode, headers, content) {
};
res.writeHead(statusCode, myheaders);
res.end(content);
+ console.log(req.method, req.url, statusCode);
};

0 comments on commit 764ea19

Please sign in to comment.
Something went wrong with that request. Please try again.