New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server.route should give a warning or show an error when accidentally providing multiple route objects as parameter instead of an array #3896

Closed
JNokikana opened this Issue Dec 19, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@JNokikana
Copy link

JNokikana commented Dec 19, 2018

Example code:

exports.plugin = {
    name: "app-routes",
    version: "1.0.0",
    register: async function (server, options) {
        server.route(
            {
                method: "POST",
                path: "/api/v1/news",
                config: {
                    handler: Handler.createNews
                }
            },
            {
                method: "GET",
                path: "/api/v1/news",
                config: {
                    handler: Handler.readNews
                }
            },
            {
                method: "DELETE",
                path: "/api/v1/news",
                config: {
                    handler: Handler.deleteNews
                }
            }
        )
    }
}

If you use the above code then only the first route works. This is because server.route expects an array of route objects and not multiple route objects. In my humble opinion the framework should throw an error or maybe a warning when you accidentally do it like this without an array. 😄 This annoyed me very much especially when I once had a typo in my code and could not at first figure out why only the first route worked. 🙈

@kanongil

This comment has been minimized.

Copy link
Member

kanongil commented Dec 19, 2018

Given destructoring, the api should probably just be reworked to server.route(...routes), and throw on arrays.

@hueniverse

This comment has been minimized.

Copy link
Member

hueniverse commented Jan 5, 2019

You can't expect the framework to validate the number of arguments passed for every api call.

@hueniverse hueniverse closed this Jan 5, 2019

@hueniverse hueniverse self-assigned this Jan 5, 2019

@hueniverse hueniverse added the non-issue label Jan 5, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment