Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q&A: How can I remove the service name from the api endpoint? #315

Closed
nnthuan opened this issue Oct 20, 2022 · 6 comments
Closed

Q&A: How can I remove the service name from the api endpoint? #315

nnthuan opened this issue Oct 20, 2022 · 6 comments
Labels

Comments

@nnthuan
Copy link

nnthuan commented Oct 20, 2022

Q&A: How can I remove the service name from the API endpoint?

When run service, API endpoint like this

/${SERVICE NAME}/products/:id <-- Auto

Expected: /products/:id


"moleculer": "^0.14.24",
"moleculer-web": "^0.10.4",

@intech
Copy link
Member

intech commented Oct 20, 2022

@nnthuan How exactly are you configuring the REST?

@nnthuan
Copy link
Author

nnthuan commented Oct 20, 2022

Hi @intech

export default class ApiService extends Service {

  public constructor(broker: ServiceBroker) {
    super(broker);
    this.parseServiceSchema({
      name: "ProductService",
      mixins: [ApiGateway],
      // More info about settings: https://moleculer.services/docs/0.14/moleculer-web.html
      settings: {
        port: process.env.PORT || 3000,
        routes: [{
          path: "/",
          ...
          }]
       },

      actions: {
               getProduct: {
                   rest: "GET /products/:id",
                   ....
               }
       }

Expected: http://localhost:3000/products/:id

Actual: http://localhost:3000/ProductService/products/:id

I don't want to have /ProductService in my endpoint.

@intech
Copy link
Member

intech commented Oct 20, 2022

export default class ApiService extends Service {

  public constructor(broker: ServiceBroker) {
    super(broker);
    this.parseServiceSchema({
      name: "ProductService",
      mixins: [ApiGateway],
      // More info about settings: https://moleculer.services/docs/0.14/moleculer-web.html
      settings: {
        port: process.env.PORT || 3000,
        routes: [{
          path: "/",
          aliases: {
              "GET /products/:id": "ProductService.getProduct"
          }
          ...
          }]
       },

      actions: {
               getProduct: {
                   ....
               }
       }

@nnthuan
Copy link
Author

nnthuan commented Oct 21, 2022

I see doing it manually through the alias, but API Gateway publishes APIs from various services, which is tired with a large amount.

Is there a setting that applies to all?

@intech
Copy link
Member

intech commented Oct 21, 2022

@nnthuan Generation automatically goes according to the rootApiPath/serverSettingsRestPath/action template. By adding step by step to the root settings of the path, setting the service path (including the version and name or option specified in the REST settings), the action path from its name (or from the REST option).

@nnthuan nnthuan closed this as completed Oct 21, 2022
@nnthuan
Copy link
Author

nnthuan commented Oct 24, 2022

Resolved

export default class ApiService extends Service {

  public constructor(broker: ServiceBroker) {
    super(broker);
    this.parseServiceSchema({
      name: "ProductService",
      mixins: [ApiGateway],
      // More info about settings: https://moleculer.services/docs/0.14/moleculer-web.html
      settings: {
        port: process.env.PORT || 3000,

         rest: '/',   // <========== HERE

        routes: [{
          path: "/",
          ...
          }]
       },

      actions: {
               getProduct: {
                   rest: "GET /products/:id",
                   ....
               }
       }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants