如何在 restFul 流星中定义 API 键?

How to define API keys in restFul meteor?

我是 meteorjs 的新手 api。我正在尝试 运行 The meteor chef 中解释的示例,但出现此错误:

ReferenceError: APIKeys is not defined
    at Object.API.authentication (api/config/api.js:4:19)
    at Object.API.connection (api/config/api.js:16:34)
    at Object.API.handleRequest (api/config/api.js:28:26)
    at [object Object].Router.route.where (api/pizza.js:9:9)
    at boundNext (packages/iron_middleware-stack/lib/middleware_stack.js:251:1)
    at runWithEnvironment (packages/meteor/dynamics_nodejs.js:110:1)
    at packages/meteor/dynamics_nodejs.js:123:1
    at [object Object].urlencodedParser (/Users/mac/.meteor/packages/iron_router/.1.0.12.13720an++os+web.browser+web.cordova/npm/node_modules/body-parser/lib/types/urlencoded.js:84:40)
    at packages/iron_router/lib/router.js:277:1
    at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)

代码与示例中解释的相同

这是因为您没有创建 APIKeys mongo 集合,如下所示:https://github.com/themeteorchef/writing-an-api/blob/master/code/collections/api-keys.js

将此文件添加到您的项目中,然后它就会工作。

这是您链接的 post 的解释:

Next, we try to insert a new key for our user into the APIKeys collection. Wait a minute! Where did this come from?! This collection was setup beforehand, but let’s talk about why we have a separate collection to begin with. The reason we want to separate our API key storage from the more predictable location of our user’s profile (the writable portion of a user’s record in the Meteor.users() collection) is that by default, the profile object is writable.

所以您刚刚错过了他们创建 APIKeys 集合的这部分教程。