如何使用Seneca和Express发送响应

我使用Seneca来路由API调用,并表示为我的文件提供服务。 问题是,我似乎无法find一种方式来从API获取我的数据后发送回应客户端的响应。 有了快递,我只是使用res.send ,但由于我在塞内加上下文,我不能。 在文档中没有find任何对此问题的提及。

 "use strict"; const bodyParser = require('body-parser'); const express = require('express'); const jsonp = require('jsonp-express'); const Promise = require('bluebird'); const path = require('path'); const seneca = require('seneca')(); const app = express(); module.exports = (function server( options ) { seneca.add('role:api,cmd:getData', getData); seneca.act('role:web',{use:{ prefix: '/api', pin: {role:'api',cmd:'*'}, map:{ getData: {GET:true} // explicitly accepting GETs } }}); app.use( seneca.export('web') ) app.use(express.static(path.join(__dirname, '../../dist/js'))) app.use(express.static(path.join(__dirname, '../../dist/public'))) app.listen(3002, function () { console.log('listening on port 3002'); }); function getData(arg, done){ //Getting data from somewhere.... //Here I would like to send back a response to the client. } }()) 

根据senecajs文档 ,您应该能够在getData方法中调用done()来返回/发送值/响应。 考虑以下:

在这里,我可以打到/api/getData并接收{foo: 'bar'}回应。

 "use strict"; const express = require('express'); const seneca = require('seneca')(); const app = express(); seneca.add('role:api,cmd:getData', getData); seneca.act('role:web',{use:{ prefix: '/api', pin: {role:'api',cmd:'*'}, map:{ getData: {GET:true} // explicitly accepting GETs } }}); app.use(seneca.export('web')); app.listen(3002, function () { console.log('listening on port 3002'); }); function getData(arg, done){ done(null, {foo: 'bar'}); }