Skip to content

Allow different names and endpoints for services... #691

@pkreipke

Description

@pkreipke

The CLI’s service generator for a Sequelize services adds a ‘name’ property to the options it passes to the service constructor.

const options = {
    name: 'items',
    Model,
    paginate
  };

  // Initialize our service with any options it requires
  app.use('/items', createService(options));

  // Get our initialized service so that we can register hooks and filters
  const service = app.service('items');
  1. However in this help page the 'name' option is never mentioned: https://docs.feathersjs.com/api/databases/sequelize.html#api .

  2. I’ve looked and stepped through the service() code and in fact it doesn’t seem to be used. Instead the leading slash is stripped off the service endpoint “/items” and into a variable location and the remaining part of the endpoint is also used as the service name.

  3. I thought the changing the line like so app.use('/restaurants', createService({name: 'item', Model, paginate} ) would allow me to mount the service on any url but it turns out that throws this error at launch:

Cannot read property 'hooks' of undefined
    at EventEmitter.module.exports
    ...

Proposed:

It would be great if the service name could actually be set by an option or argument such that a common service name and its code could be reused in multiple apps/projects and only the service's route changed.

Use case:

A reusable service "items" provides the same CRUD implementation (fields, computed fields, custom processing etc) for an "item" but each app that requires/includes the service could have the route be specific to its type/client in that particular app (/restaurants, /groceries, /movies, /todo etc ).

Notes:

  • not sure: perhaps rename the service by doing find/replace in the services[] array as long as the service's actual route isn't ret-conned from location in turn.

  • or perhaps vice versa: create service "items" first and then overwrite the endpoint with '/restaurants'. Issue Unregistering services and hooks #446 implies that maybe can only do in REST - because of needing to unbind from transports. So this might not be an option.

Related:

  • This is a similar thing: using Sequelize I'm able to have an actual DB table name be different than whatever I call the JS model by modifying the generated code. But that doesn't apply to the service's options.name field

  • issue Unregistering services and hooks #446 also talks about unregistering services after they're live but was removed from Buzzard. And I'm not looking for hot swapping, just intelligent options during setup

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions