我正在尝试使用 feathersjs,但我无法通过示例程序(feathers.js 主站点上的待办事项列表)。唯一传递给函数的是接收到的数据。param
并且callback
总是未定义的。
var myService = {
find: function(params, callback) {},
get: function(id, params, callback) {},
create: function(data, params, callback) {},
update: function(id, data, params, callback) {},
patch: function(id, data, params, callback) {},
remove: function(id, params, callback) {},
setup: function(app, path) {}
}
我做错了什么?我需要使用旧版本吗?我目前在我的羽毛中使用“最新”package.json
编辑:
我从字面上复制粘贴了来自http://feathersjs.com/#documentation的示例代码
编辑:源文件添加:
// app.js
var bodyParser = require("body-parser");
var compression = require("compression");
var express = require("express");
var feathers = require("feathers");
var http = require("http");
var io = require("socket.io");
var v1 = require("./lib/v1");
var config = require("./lib/config");
var app = feathers()
.configure(feathers.socketio())
.use(bodyParser.json())
.use("/v1", v1)
var port = process.env.PORT || 3000;
app.listen(port);
和
//lib/v1.js
var v1Service = {
find: function(params, callback) {
console.log("finding");
callback(null, [{
"uuid": "blahblahblah"
}]);
},
get: function(id, params, callback) {
console.log("geting");
callback(null, {
"uuid": "blahblahblah"
});
},
create: function(data, params, callback) {
console.log("creating, args:" + JSON.stringify(callback));
callback(null, {
"uuid": "blahblahblah"
});
},
update: function(id, data, params, callback) {
console.log("updating");
callback(null, {
"uuid": "blahblahblah"
});
},
patch: function(id, data, params, callback) {
console.log("patching");
callback(null, {
"uuid": "blahblahblah"
});
},
remove: function(id, params, callback) {
console.log("removeing");
callback(null, {
"uuid": "blahblahblah"
});
},
setup: function(app, path) {
console.log("setup");
}
}
module.exports = v1Service;
编辑:添加错误
TypeError: undefined is not a function
at Object.v1Service.get [as _super] (/api_dev/lib/v1.js:11:3)
at Object.<anonymous> (/api/node_modules/feathers/lib/mixins/promise.js:6:30)
at Object.self.(anonymous function) [as get] (/api/node_modules/feathers/node_modules/uberproto/lib/proto.js:61:21)
at Socket.<anonymous> (/api/node_modules/feathers/lib/providers/socket/commons.js:27:23)
at Socket.EventEmitter.emit (events.js:95:17)
at Socket.onevent (/api/node_modules/socket.io/lib/socket.js:327:8)
at Socket.onpacket (/api/node_modules/socket.io/lib/socket.js:287:12)
at Client.ondecoded (/api/node_modules/socket.io/lib/client.js:185:14)
at Decoder.Emitter.emit (/api/node_modules/socket.io/node_modules/socket.io-parser/node_modules/component-emitter/index.js:134:20)
at Decoder.add (/api/node_modules/socket.io/node_modules/socket.io-parser/index.js:247:12)