1

我正在使用我想在我的 React-Redux-Webpack 应用程序的操作中导入的 ES6 类设置一个羽毛客户端。

我已经使用很棒的 Feathers 脚手架设置了一个 REST api。

不幸的是,我在浏览器中遇到了一个错误,这毁了我的一天。我究竟做错了什么?

未捕获的 TypeError:_client2.default.hooks 不是函数

谁能帮我吗?为什么hooks(也rest)在这里未定义?软件包似乎已正确安装...

以下是个好主意吗?

// src/middleware/api.js

import hooks from 'feathers-hooks'
import feathers from 'feathers/client'
import rest from 'feathers-rest/client'

class API {
  constructor() {
    const connection = process.env.FEATHERS_API_URL
    this.app = feathers()
      .configure(feathers.hooks())
      .configure(rest(connection).fetch(fetch))
      .configure(feathers.authentication({
        type: 'local',
        storage: window.localStorage,
      }))
  }
}

会不会是某些包不兼容?

"feathers": "^2.0.3",
    "feathers-authentication": "^0.7.12",
    "feathers-client": "^1.8.0",
    "feathers-configuration": "^0.3.3",
    "feathers-errors": "^2.5.0",
    "feathers-hooks": "^1.7.1",
    "feathers-rest": "^1.5.2",
    "feathers-sequelize": "^1.4.0"

我想知道的另一件事是我们是否总是需要为rest函数提供路径?可以默认使用配置文件中使用的路径吗?让我的客户端和服务器端代码在同一个项目中,给它提供一条路径感觉有点奇怪......

4

1 回答 1

2

@feathersjs/client是一个包含一组 Feathers 标准模块(如 auth、rest、socketio 客户端)的包,可以直接在浏览器中使用(请参阅此处的文档)。

看起来您正在尝试使用此处记录的模块加载器,因此您可以只导入您需要的模块并配置它们,而不是使用预先捆绑的包(所有东西都在feathers.命名空间中feathers.hooks,等等):feathers.authentication

  // src/middleware/api.js
  import feathers from '@feathersjs/feathers'
  import rest from '@feathersjs/rest-client'
  import authentication from '@feathersjs/authentication-client'

  class API {
    constructor() {
      const connection = process.env.FEATHERS_API_URL
      this.app = feathers()
        .configure(rest(connection).fetch(fetch))
        .configure(authentication({
          type: 'local',
          storage: window.localStorage,
        }))
    }
  }

rest如果它在同一个域上运行,则不需要基本 url。默认为空字符串。

于 2016-12-20T00:55:10.537 回答