Feathersjs API ES6 class hooks 和 rest undefined
Feathersjs API ES6 class hooks and rest undefined
我正在使用 ES6 class 设置一个羽毛客户端,我想将其导入到我的 React-Redux-Webpack 应用程序的操作中。
我已经使用很棒的 Feathers 脚手架设置了 REST api。
不幸的是,我在浏览器中遇到一个错误,这毁了我的一天。我做错了什么?
Uncaught TypeError: _client2.default.hooks is not a function
谁能帮帮我?为什么 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
函数提供路径?它可以默认使用配置文件中使用的路径吗?将我的客户端和服务器端代码都放在同一个项目中,给它提供一条路径感觉有点奇怪...
@feathersjs/client
是一个包含一组 Feathers 标准模块(如 auth、rest、socketio 客户端)的包,可以直接在浏览器中使用(参见 the documentation here)。
您似乎在尝试使用模块加载器 which is documented here,因此您没有使用预先捆绑的包(所有内容都在 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。默认为空字符串。
我正在使用 ES6 class 设置一个羽毛客户端,我想将其导入到我的 React-Redux-Webpack 应用程序的操作中。
我已经使用很棒的 Feathers 脚手架设置了 REST api。
不幸的是,我在浏览器中遇到一个错误,这毁了我的一天。我做错了什么?
Uncaught TypeError: _client2.default.hooks is not a function
谁能帮帮我?为什么 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
函数提供路径?它可以默认使用配置文件中使用的路径吗?将我的客户端和服务器端代码都放在同一个项目中,给它提供一条路径感觉有点奇怪...
@feathersjs/client
是一个包含一组 Feathers 标准模块(如 auth、rest、socketio 客户端)的包,可以直接在浏览器中使用(参见 the documentation here)。
您似乎在尝试使用模块加载器 which is documented here,因此您没有使用预先捆绑的包(所有内容都在 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。默认为空字符串。