Skip to content

Latest commit

 

History

History
316 lines (247 loc) · 7.1 KB

CHANGELOG.md

File metadata and controls

316 lines (247 loc) · 7.1 KB

0.5.2 (2017-10-24)

New

  • add mappingPolicy route option

0.5.1 (2017-10-07)

New

  • add CORS headers
  • add Rate limiter

0.5.0 (2017-09-12)

Breaking changes

  • compatibility with Moleculer >= v0.11.x

0.4.4 (2017-08-20)

Changes

  • update Moleculer to v0.10

0.4.1 (2017-07-24)

New

Prohibited action with publish: false action properties

module.exports = {
    name: "test",
    actions: {
        dangerZone: {
            publish: false,
            handler(ctx) {
                return "You cannot call this action via API Gateway!";
            }
        }
    }
};

Calling options in routes

The route has a callOptions property which is passed to broker.call. So you can set timeout, retryCount or fallbackResponse options for routes.

broker.createService(ApiGatewayService, {
    settings: {
        routes: [{
            
            callOptions: {
                timeout: 1000, // 1 sec
                retryCount: 0,
                //fallbackResponse: { ... },
                // or 
                //fallbackResponse(ctx, err) { ... }
            }

        }]
    }
});

0.4.0 (2017-07-07)

Breaking changes

  • in the REST shorthand, the GET / calls the list action instead of find. The reason is list action in moleculer-db is support pagination

Changes

  • changed order of param handling ctx.params = Object.assign({}, body, query, params).
  • moved onBeforeCall before authorize in request flow. So you can also reach unauthorized requests in onBeforeCall handler.
  • the sendResponse method has new arguments: sendResponse(ctx, route, req, res, data, responseType)

0.3.3 (2017-06-07)

New

Functions in aliases

There is available to use custom function in aliases. In this case you got req & res and you should return with the response. Use it for example file uploads. You can find example in the full example.

Usage

    ...
        aliases: {
            "add/:a/:b": "math.add",
            "GET sub": "math.sub",
            "POST upload"(route, req, res) {
                //Do something and call res.end()
            }
        }
    ...

New camelCaseNames route setting

There is a new camelCaseNames option in route setting. If it is true, the service will convert the received action name to camelCase name.

Usage

broker.createService(ApiGatewayService, {
    settings: {
        routes: [{
            camelCaseNames: true
        }]
    }
});

broker.createService({
    name: "test",
    actions: {
        sayHi(ctx) {
            return "Hi!"
        }
    }
});

// Start server
broker.start();

In the above example the sayHi action can be called with http://localhost:3000/test/say-hi as well.


0.3.2 (2017-06-02)

New

Exposed error classes

Available errors:

Class Params Description
UnAuthorizedError type, data Unauthorized HTTP error (401)
ForbiddenError type, data Forbidden HTTP error (403)
BadRequestError type, data Bad Request HTTP error (400)

Type contants:

  • ERR_NO_TOKEN
  • ERR_INVALID_TOKEN
  • ERR_UNABLE_DECODE_PARAM

Usage

const { UnAuthorizedError, ERR_NO_TOKEN } = require("moleculer-web").Errors;
    ...
    actions: {
        update(ctx) {
            if(!ctx.meta.user)
                return Promise.reject(new UnAuthorizedError(ERR_NO_TOKEN));
        }
    }
    ...

0.3.1 (2017-06-02)

New

RESTful routes

It is possible to use RESTful aliases which routed to CRUD service actions.

Usage

broker.createService(ApiGatewayService, {
    settings: {
        routes: [{
            // RESTful aliases
            aliases: {
                "REST posts": "posts"
            }
        }]
    }
});

// Start server
broker.start();

The "REST posts": "posts" will be extracted to these aliases:

"GET posts":        "posts.find",
"GET posts/:id":    "posts.get",
"POST posts":       "posts.create",
"PUT posts/:id":    "posts.update",
"DELETE posts/:id": "posts.remove"				

Example: examples/rest


0.3.0 (2017-06-01)

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


0.2.2 (2017-06-01)

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


0.2.1 (2017-05-23)

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


0.2.0 (2017-05-09)

New

Support custom authorization

For more information check the full or authorization examples or readme


0.1.0 (2017-05-08)

First release.