使用 feathersjs 自定义 service/route 创建

Custom service/route creation using feathersjs

我最近 2 天一直在阅读文档。我是 feathersjs.

的新手

第一期:无法访问与feathersjs相关的任何link。比如this.

出现以下错误:

This page isn’t working

legacy.docs.feathersjs.com redirected you too many times.

因此我无法回溯到类似类型或任何类型的先前询问过的线程。

第二期:这是一个很好的实时应用框架。但并非所有实时应用程序都只需要单独的数据库访问,它们可能需要访问 Amazon S3、Microsoft Azure 等。在我的情况下,它是相同的,更像是设置问题向上路线。

我执行了以下命令:

feathers generate app

feathers generate service服务名称:上传,REST,DB:Mongoose)

feathers generate authentication用户名和密码

我已经准备好了设置,但是 我如何添加另一个自定义服务?

服务的粒度以下列方式开始(Use case only for upload):

常规方法 >> router.post('/upload', (req, res, next) =>{});

假设,我正在使用数据表单发送 file,并在请求中发送一些额外的参数,例如 { storage: "s3"}

Postman --> POST (Only) to /upload ---> Process request (isStorageExistsInRequest?) --> 然后分别执行实际上传到具体的Storage中请求并在本地数据库中记录详细信息 --> 发送响应 (Success or Failure)

关于堆栈溢出,您回答的是:

app.use('/Category/ExclusiveContents/:categoryId', {
  create(data, params) {
  // do complex stuff here
  params.categoryId // the id of the category
  data // -> additional data from the POST request
 }
});

解决方案也可以这样看,因为featherjs支持微服务方式,如果有这样的子路由就好了:

/upload_s3 -- 上传到 s3

/upload_azure -- 上传到azure等。

/upload -- 暴露给用户的主路由。用户请求,处理请求,调用各自的子路由。 (还要包括身份验证和授权)

如何使用现有的 feathersjs 设置解决这些类型的问题?

1) 这是一个部署问题,Netlify 正在调查。虽然当前文档不在遗留域中,但您可以在 docs.feathersjs.com/api/databases/querying.html.

中找到您要查找的内容

2) 可以通过 运行 feathers generate service 并选择自定义服务选项来添加自定义服务。然后可以根据 service interface. For file uploads, an example on how to customize the parameters for feathers-blob (which is used in the file uploading guide) can be found in this issue.

src/services/<service-name>/<service-name>.class.js 中实现功能