Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

moleculer-web

Package Overview
Dependencies
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

moleculer-web

Official API Gateway service for Moleculer framework

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14K
decreased by-8.09%
Maintainers
1
Weekly downloads
 
Created
Source

Moleculer logo

Build Status Coverage Status Codacy Badge Code Climate David Known Vulnerabilities Join the chat at https://gitter.im/ice-services/moleculer

Official API Gateway for Moleculer framework NPM version

The moleculer-web is the official API gateway service for Moleculer. Use it to publish your services.

Features

  • support HTTP & HTTPS
  • serve static files
  • multiple routes
  • alias names
  • whitelist
  • multiple body parsers (json, urlencoded)
  • Buffer & Stream handling

Install

npm install moleculer-web --save

Usage

Run with default settings

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");

// Create broker
let broker = new ServiceBroker();

// Load your services
broker.loadService(...);

// Load API Gateway
broker.createService(ApiService);

// Start server
broker.start();

Example URLs:

  • Call test.hello action: http://localhost:3000/test/hello

  • Call math.add action with params: http://localhost:3000/math/add?a=25&b=13

  • Get health info of node: http://localhost:3000/~node/health

  • List all actions: http://localhost:3000/~node/actions

Service settings

settings: {

	// Exposed port
	port: process.env.PORT || 4000,

	// Exposed IP
	ip: process.env.IP || "0.0.0.0",

	// HTTPS server with certificate
	https: {
		key: fs.readFileSync("ssl/key.pem"),
		cert: fs.readFileSync("ssl/cert.pem")
	},

	// Exposed path prefix
	path: "/api",

	// Routes
	routes: [
		{
			// Path prefix to this route  (full path: /api/admin )
			path: "/admin",

			// Whitelist of actions (array of string mask or regex)
			whitelist: [
				"users.get",
				"$node.*"
			],

			// Under development
			authorization: true,

			// Action aliases
			aliases: {
				"POST users": "users.create",
				"health": "$node.health"
			},

			// Use bodyparser module
			bodyParsers: {
				json: true,
				urlencoded: { extended: true }
			}
		},
		{
			// Path prefix to this route  (full path: /api )
			path: "",

			// Whitelist of actions (array of string mask or regex)
			whitelist: [
				"posts.*",
				"file.*",
				/^math\.\w+$/
			],

			authorization: false,
			
			// Action aliases
			aliases: {
				"add": "math.add",
				"GET sub": "math.sub",
				"POST divide": "math.div",
			},
			
			// Use bodyparser module
			bodyParsers: {
				json: false,
				urlencoded: { extended: true }
			}
		}
	],

	// Folder to server assets (static files)
	assets: {

		// Root folder of assets
		folder: "./examples/www/assets",
		
		// Options to `server-static` module
		options: {}
	}
}

Examples

Test

$ npm test

In development with watching

$ npm run ci

Contribution

Please send pull requests improving the usage and fixing bugs, improving documentation and providing better examples, or providing some testing, because these things are important.

License

Moleculer-web is available under the MIT license.

Contact

Copyright (c) 2017 Ice-Services

@icebob @icebob

Keywords

FAQs

Package last updated on 08 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc