Search code examples
feathersjs

Custom service/route creation using feathersjs


I have been reading the documentation for last 2 days. I'm new to feathersjs.

First issue: any link related to feathersjs is not accessible. Such as this.

Giving the following error:

This page isn’t working

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

Hence I'm unable to traceback to similar types or any types of previously asked threads.

Second issue: It's a great framework to start with Real-time applications. But not all real time application just require alone DB access, their might be access required to something like Amazon S3, Microsoft Azure etc. In my case it's the same and it's more like problem with setting up routes.

I have executed the following commands:

feathers generate app

feathers generate service (service name: upload, REST, DB: Mongoose)

feathers generate authentication (username and password)

I have the setup with me, ready but how do I add another custom service?

The granularity of the service starts in the following way (Use case only for upload):

Conventional way of doing it >> router.post('/upload', (req, res, next) =>{});

Assume, I'm sending a file using data form, and some extra param like { storage: "s3"} in the req.

Postman --> POST (Only) to /upload ---> Process request (isStorageExistsInRequest?) --> Then perform the actual upload respectively to the specific Storage in Req and log the details in local db as well --> Send Response (Success or Failure)

Another thread on stack overflow where you have answered with this:

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
 }
});

The solution can viewed in this way as well, since featherjs supports micro service approach, It would be great to have sub-routes like:

/upload_s3 -- uploads to s3

/upload_azure -- uploads to azure and so on.

/upload -- main route which is exposed to users. User requests, process request, call the respective sub-route. (Authentication and Auth to be included as well)

How to solve these types of problems using existing setup of feathersjs?


Solution

  • 1) This is a deployment issue, Netlify is looking into it. The current documentation is not on the legacy domain though, what you are looking for can be found at docs.feathersjs.com/api/databases/querying.html.

    2) A custom service can be added by running feathers generate service and choosing the custom service option. The functionality can then be implemented in src/services/<service-name>/<service-name>.class.js according to the 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.