Skip to content
Browse files

improve logging around head requests

  • Loading branch information...
1 parent 08f8fe7 commit 95c54e9e146ea3f6b83c14d1d517a8cb1ce44fdd @omphalos committed Aug 4, 2012
Showing with 6 additions and 2 deletions.
  1. +5 −1 crud-file-server.js
  2. +1 −1 package.json
View
6 crud-file-server.js
@@ -51,14 +51,14 @@ exports.handleRequest = function(vpath, path, req, res, readOnly) {
var relativePath = vpath ?
path + url.slice(vpath.length + 1, url.length):
path + url;
- console.log('relativePath: ' + relativePath);
try {
if(readOnly && req.method != 'GET') {
writeError(req.method + ' forbidden on this resource', 403);
} else {
switch(req.method) {
case 'HEAD':
+ // console.log('head: ' + relativePath);
fs.stat(relativePath, function(err, stats) { // determine if the resource is a file or directory
if(err) { writeError(err); }
else {
@@ -69,6 +69,7 @@ exports.handleRequest = function(vpath, path, req, res, readOnly) {
});
break;
case 'GET': // returns file or directory contents
+ console.log('relativePath: ' + relativePath);
if(url === 'favicon.ico') {
res.end(); // if the browser requests favicon, just return an empty response
} else {
@@ -121,6 +122,7 @@ exports.handleRequest = function(vpath, path, req, res, readOnly) {
return;
case 'POST': // create a directory or rename a file or directory
if(query.rename) { // rename a file or directory
+ console.log('rename: ' + relativePath);
// e.g., http://localhost/old-name.html?rename=new-name.html
query.rename = cleanUrl(query.rename);
if(vpath) {
@@ -147,6 +149,7 @@ exports.handleRequest = function(vpath, path, req, res, readOnly) {
}
});
} else {
+ console.log('relativePath: ' + relativePath);
writeError('valid queries are ' + url + '?rename=[new name] or ' + url + '?create=directory');
}
return;
@@ -171,6 +174,7 @@ exports.handleRequest = function(vpath, path, req, res, readOnly) {
});
return;
default: // unsupported method! tell the client ...
+ console.log('unsupported: ' + relativePath);
writeError('Method ' + method + ' not allowed', 405);
return;
}
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "crud-file-server",
- "version": "0.1.1",
+ "version": "0.1.2",
"description": "file server supporting basic create, read, update, & delete for any kind of file",
"bin": {
"crud-file-server": "./bin/crud-file-server"

0 comments on commit 95c54e9

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