Skip to content

Commit 95025bf

Browse files
committed
Fix several bugs in the promise-based file server
1 parent 84f3991 commit 95025bf

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

code/file_server_promises.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ http.createServer(function(request, response) {
2222
else
2323
response.end(data.body);
2424
}, function(error) {
25-
response.writeHead(500, error.toString());
25+
response.writeHead(500);
26+
response.end(error.toString());
2627
console.log("Response failed: ", error.stack);
2728
});
2829
}).listen(8000);
@@ -31,8 +32,8 @@ function respondTo(request) {
3132
if (request.method in methods)
3233
return methods[request.method](urlToPath(request.url), request);
3334
else
34-
return {code: 405,
35-
body: "Method " + request.method + " not allowed."};
35+
return Promise.resolve({code: 405,
36+
body: "Method " + request.method + " not allowed."});
3637
}
3738

3839
function urlToPath(url) {
@@ -51,7 +52,7 @@ var fsp = {};
5152
});
5253

5354
// Since several functions need to call `fsp.stat` and handle failures
54-
// that indicate non-existant files in a special way, this is a
55+
// that indicate non-existent files in a special way, this is a
5556
// convenience wrapper that converts file-not-found failures into
5657
// success with a null value.
5758
//

0 commit comments

Comments
 (0)