The moleculer-web
is the official API gateway service for Moleculer. Use it to publish your services.
npm install moleculer-web --save
This example uses API Gateway service with default settings.
You can access to all services (including internal $node.
) via http://localhost:3000/
let { ServiceBroker } = require("moleculer");
let ApiService = require("moleculer-web");
let broker = new ServiceBroker({ logger: console });
// Create a service
broker.createService({
name: "test",
actions: {
hello() {
return "Hello API Gateway!"
}
}
});
// Load API Gateway
broker.createService(ApiService);
// Start server
broker.start();
Test URLs:
Call test.hello
action: http://localhost:3000/test/hello
Get health info of node: http://localhost:3000/~node/health
List all actions: http://localhost:3000/~node/actions
Please read our documentation on Moleculer site
$ npm test
In development with watching
$ npm run ci
Moleculer-web is available under the MIT license.
Copyright (c) 2016-2021 MoleculerJS