moleculerjs / moleculer-web

:earth_africa: Official API Gateway service for Moleculer framework
http://moleculer.services/docs/moleculer-web.html
MIT License
291 stars 119 forks source link

Add named-routes #273

Closed icebob closed 2 years ago

icebob commented 2 years ago

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
            }
        ]
    }
};