Serve files without listening to request end event

This commit is contained in:
Zaid Abdulla committed 2013-03-31 16:05:51 +03:00
1 parent 03e57616f7
commit 5934178d91
1 file changed
+9 -11
+9 -11
View File
@@ -28,17 +28,15 @@ else
server = http.createServer((request, response) ->
urlParts = url.parse(request.url, true)
if request.method == 'GET'
request.addListener('end', () ->
gs = new mongodb.GridStore(db, urlParts.pathname.substring(1), 'r', {})
gs.open((err, gs) ->
if err
response.writeHead(404)
response.end()
return
stream = gs.stream(true)
response.writeHead(200)
stream.pipe(response)
)
gs = new mongodb.GridStore(db, urlParts.pathname.substring(1), 'r', {})
gs.open((err, gs) ->
if err
response.writeHead(404)
response.end()
return
stream = gs.stream(true)
response.writeHead(200)
stream.pipe(response)
)
else
response.writeHead(405, {'Allow': 'GET'})