Closed yogesh-rs closed 3 years ago
Can you please add the actual code to reproduce the issue?
Steps to reproduce this issue:
greetings.service.js
as shown belownpm run dev
So far no issues
Navigate to Services
tab
There are no services listed and in the console, you get the error messages described in the issue reported by @yogesh-rs
// greetings.service.js
"use strict";
/**
* @typedef {import('moleculer').Context} Context Moleculer's Context
*/
// https://github.com/moleculerjs/moleculer-http-client
const HTTPClientService = require('moleculer-http-client');
module.exports = {
name: "greeter",
mixins: [HTTPClientService],
/**
* Settings
*/
settings: {
},
/**
* Dependencies
*/
dependencies: [],
/**
* Actions
*/
actions: {
/**
* Say a 'Hello' action.
*
* @returns
*/
hello: {
rest: {
method: "GET",
path: "/hello"
},
async handler() {
return this.hello();
}
},
/**
* Welcome, a username
*
* @param {String} name - User name
*/
welcome: {
rest: "/welcome",
async handler() {
return this.welcome();
}
}
},
/**
* Events
*/
events: {
},
/**
* Methods
*/
methods: {
async hello() {
this.broker.call("greeter.get", {
url: "https://httpbin.org/json",
opt: { responseType: "json" }
})
.then(res => this.broker.logger.info(res))
.catch(error => this.broker.logger.error(error));
},
async welcome() {
this._get("https://httpbin.org/json", { responseType: "json" })
.then(res => this.broker.logger.info(res))
.catch(error => this.broker.logger.error(error));
},
},
/**
* Service created lifecycle event handler
*/
created() {
},
/**
* Service started lifecycle event handler
*/
async started() {
},
/**
* Service stopped lifecycle event handler
*/
async stopped() {
}
};
Thanks @arun-prakash-fokus I've fixed the issue and released it in v0.4.1
Thank you for the quick fix.
On another note, we have the actions from the HTTPClientService
shown through the API gateway for the greeter
service. Is this the expected behavior?
may i suggest adding
visibility: "private",
to the HTTP actions
provided by the HttpClientService
. This way, when mixed in, they are still available to the local service, but not visible through the gateway.
Thoughts & comments
Yes, by default all actions are public and visible. However, you can mark them as private or even remove them, if necessary, by adapting the method filtering example
const HTTPClientService = require("moleculer-http-client");
mixins: [HTTPClientService],
// this line throws an error in consolenpm run dev
--
Result :
/API: <= 500 GET /api/~node/services?withActions=true [+15.368 ms]