Skip to content

Releases: moleculerjs/moleculer-web

v0.3.0

02 Jun 18:02
Compare
Choose a tag to compare

New

Named parameters in aliases

It is possible to use named parameters in aliases. Named paramters are defined by prefixing a colon to the parameter name (:name)

Usage

broker.createService(ApiGatewayService, {
    settings: {
        routes: [{
            path: "/api",

            aliases: {
                "GET greeter/:name": "test.greeter",
                "optinal-param/:name?": "test.echo",
                "repeat-param/:args*": "test.echo",
                "GET /": "test.hello"                
            }
        }]
    }
});

// Start server
broker.start();

Example: examples/full

v0.2.3

01 Jun 10:09
Compare
Choose a tag to compare

New

Before & after call hooks

The route of service has onBeforeCall and onAfterCall hooks. It can be asynchronous if return with Promise. In methods the this is pointed to Service instance. So you can access the service methods & broker.

Usage

broker.createService(ApiGatewayService, {
    settings: {
        routes: [{
            // Call before `broker.call`
            onBeforeCall(ctx, route, req, res) {
                // Save request headers to context meta
                ctx.meta.userAgent = req.headers["user-agent"];
            },

            // Call after `broker.call` and before send back the response
            onAfterCall(ctx, route, req, res, data) {
                res.setHeader("X-Custom-Header", "123456");
            }
        }]
    }
});

// Start server
broker.start();

Example: examples/full

v0.2.2

23 May 09:19
Compare
Choose a tag to compare

New

ExpressJS middleware usage

You can use Moleculer-Web as a middleware for ExpressJS.

Usage

const svc = broker.createService(ApiGatewayService, {
	settings: {
		middleware: true
	}
});

// Create Express application
const app = express();

// Use ApiGateway as middleware
app.use("/api", svc.express());

// Listening
app.listen(3000);

// Start server
broker.start();

Example: examples/express

v0.2.0

09 May 09:54
Compare
Choose a tag to compare

Support custom authorization

For more information check the full or authorization examples or readme

First release

08 May 13:38
Compare
Choose a tag to compare

Features

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

Full 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.*"
			],

			// 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+$/
			],

			// 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: {}
	}
}