Closed nnthuan closed 2 years ago
@nnthuan How exactly are you configuring the REST?
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.
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: {
....
}
}
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?
@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).
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",
....
}
}
Q&A: How can I remove the service name from the API endpoint?
When run service, API endpoint like this
/${SERVICE NAME}/products/:id
<-- AutoExpected:
/products/:id
"moleculer": "^0.14.24", "moleculer-web": "^0.10.4",