我有一个快速应用程序可以处理如下所示的发布请求(coffeescript)
#Handle CSV Uploads
app.post '/upload', (req, res) ->
res.setHeader 'Content-Type', 'text/json'
if !req.session.user?
res.json
success: false
return
if !req.files.files? || !req.files.files.length
res.json
success: false
message: 'No Files Uploaded'
return
file = req.files.files[0]
if file.mime is not 'text/csv'
res.json
success: false
message: 'Invalid Upload Type'
return
#Find IDs of all shippers referenced in this csv
client_shippers_ids = []
chainer = new Sequelize.Utils.QueryChainer
csv()
.from.stream(fs.createReadStream(file.path))
.to.path('/tmp/tempcsv.out')
.transform((row) ->
return row
).on('record', (row, index)->
chainer.add DB.Order.create
po_num: Math.random() + ''
description: Math.random() + ''
requested_by: ''
received: false
status: 'Purchase Order Received'
).on('end', (count)->
console.log 'end'
console.log count
chainer.run().success () ->
console.log 'chainer fin'
res.json #<----- This part does not send
success: true
message: 'complete'
)
特别是这个电话
res.json #<----- This part does not send
success: true
message: 'complete'
不返回任何东西。在此之前是否调用了 res.end() ?