Skip to content

Releases: moleculerjs/moleculer-web

v0.11.0-beta2

11 Jun 19:54
Compare
Choose a tag to compare
v0.11.0-beta2 Pre-release
Pre-release

Changes

BREAKING: Minimum Node 20

The minimum Node version is Node 20.x.

BREAKING: Update dependencies

Many dependencies (major, minor, patch) is upgraded which can contain breaking changes

Full Changelog: v0.11.0-beta1...v0.11.0-beta2

v0.10.8

24 Mar 17:40
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v0.10.7...v0.10.8

v0.11.0-beta1

04 Dec 21:29
Compare
Choose a tag to compare
v0.11.0-beta1 Pre-release
Pre-release

Full Changelog: v0.10.7...v0.11.0-beta1

Changes

Updated path-ro-regexp library

The path-to-regexp has been updated to 8.x.x. It contains many breaking changes in the path resolving. Check the documentation of library to how migrate your alias paths.

Optional parameter alias path

    // Old way
    "GET user/:name?": "user.get"

    // New way
    "GET user{/:name}": "user.get"

Repeating parameter alias path

    // Old way
    "GET /users/*username": "user.resolveUsersByNames",

    // New way
    "GET /users/:username*": "user.resolveUsersByNames",

Using 0.15 new streaming solution

The [email protected] supports Moleculer v0.15.x including the new streaming solution. It means, it doesn't support 0.13 and 0.14 moleculer versions.

Thanks for the new solution, the multipart fields and request parameters are sent via ctx.params instead of meta and the file stream is available in ctx.stream in action handlers.

Example

module.exports = {
    name: "file",
    actions: {
        save: {
            handler(ctx) {
                return new this.Promise((resolve, reject) => {
                    const filePath = path.join(uploadDir, ctx.params.$filename);
                    const f = fs.createWriteStream(filePath);
                    f.on("close", () => {
                        // File written successfully
                        this.logger.info(`Uploaded file stored in '${filePath}'`);
                        resolve({ filePath });
                    });

                    ctx.stream.on("error", err => {
                        this.logger.info("File error received", err.message);
                        reject(err);

                        // Destroy the local file
                        f.destroy(err);
                    });

                    f.on("error", () => {
                        // Remove the errored file.
                        fs.unlinkSync(filePath);
                    });

                    ctx.stream.pipe(f);
                });
            }
        }
    }
};

Example content of ctx.params:

{
    // Multipart file properties
    $fieldname: "myfile", 
    $filename: "avatar.png",
    $encoding: "7bit",
    $mimetype: "image/png",
    
    // Other multipart fields
    // e.g.: `<input type="text" name="name" id="name" value="Test User">`
    name: "Test User", 

    // Request path parameter, e.g.: `/upload/single/1234`
    id: "1234" 
}

v0.10.7

12 Nov 18:12
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v0.10.6...v0.10.7

v0.10.6

15 Jul 17:35
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v0.10.5...v0.10.6

v0.10.5

17 Dec 16:22
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v0.10.4...v0.10.5

v0.10.4

09 Jan 10:06
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v0.10.3...v0.10.4

v0.10.3

17 Oct 13:49
Compare
Choose a tag to compare

Named authenticate & authorize methods #275

You can define custom authentication and authorization methods for every routes. In this case you should set the method name instead of true value.

module.exports = {
    mixins: ApiGatewayService,

    settings: {

        routes: [
            {
                path: "/aaa",
                authentication: "aaaAuthn",
                authorization: "aaaAuthz",
                aliases: {
                    "GET hello": "test.hello"
                }
            },
            {
                path: "/bbb",
                authentication: "bbbAuthn",
                authorization: "bbbAuthz",
                aliases: {
                    "GET hello": "test.hello"
                }
            },
            {
                path: "/ccc",
                authentication: true,
                authorization: true,
                aliases: {
                    "GET hello": "test.hello"
                }
            }
        ]
    },

    methods: {
        aaaAuthn() {
            // ... do authn
        },
        aaaAuthz() {
            // ... do authz
        },

        bbbAuthn() {
            // ... do authn
        },
        bbbAuthz() {
            // ... do authz
        },

        authenticate() {
            // ... do authn
        },
        authorize() {
            // ... do authz
        }
    }
}

Configure rate limit options in routes level

module.exports = {
    name: 'api',
    mixins: [ApiGateway],
    settings: {
        rateLimit: rateLimitGlobalConfig,
        routes: [
            {
                path: '/withLocalRateLimit',
                // now you can pass rateLimit here
                // it will override the global rateLimit
                rateLimit: rateLimitConfig,
                aliases: {
                    'GET /2': 'test.2'
                }
            },
            {
                path: '/withGlobalRateLimit',
                aliases: {
                    'GET /1': 'test.1'
                }
            }
        ]
    }
}

Other changes

  • update dependencies.
  • add support for custom cors origin function. #274
  • typescript definition file is rewritten. #259

v0.10.2

05 Sep 15:38
Compare
Choose a tag to compare

Named routes

Many developers issued that version 0.10 doesn't support multiple routes with the same path. This version fixes it but you should give a unique name for the routes if they have same path.

Example
You can call /api/hi without auth, but /api/hello only with auth.

const ApiGateway = require("moleculer-web");

module.exports = {
    mixins: [ApiGateway],
    settings: {
        path: "/api",

        routes: [
            {
                name: "no-auth-route", // unique name
                path: "/",
                aliases: {
                    hi: "greeter.hello",
                }
            },
            {
                name: "with-auth-route", // unique name
                path: "/",
                aliases: {
                    "hello": "greeter.hello",
                },
                authorization: true
            }
        ]
    }
};

Changes

  • add removeRouteByName(name: string) method to remove a route by its name.

v0.10.1

01 Sep 17:29
Compare
Choose a tag to compare

Changes

  • set the default JSON bodyparser if bodyParser: true. #258
  • add pathToRegexpOptions to route options to make available to pass options to path-to-regexp library. #268
  • add debounceTime to route options to make available to change the debounce time at service changes. #260
  • new errorHandler method to allow developers to change the default error handling behaviour. #266
  • fixes CORS preflight request handling in case of full-path aliases. #269
  • update dependencies