imrefazekas / connect-rest

Exceptionally featureful Restful web services middleware for connect node.js
MIT License
100 stars 29 forks source link

"/" default behavior for matching routes? #19

Closed jlg7 closed 10 years ago

jlg7 commented 10 years ago

Hi,

Thank you for the node module. It is working great for me. Just trying get clarification around default expected behavior when matching routes, I have a declaration style like this:

        var connect = require('connect');
        var rest = require('connect-rest');
        var app = connect();

        app.use(
            rest.rester(
                {
                    context:'/'
                }
            )
        );
 rest.get(
            [{ path: '/distributions/:name', version: '>=1.0.0'}],
            function(request,content,callback){
            });

"/" is matching all routes which is suspect.

Let me know if you need any additional info.

Thanks, @jongeho1

imrefazekas commented 10 years ago

Hello, The path matching is quite simple. The context + your path concatenated should match with the requested URI. Let me run a few tests on your code.

BTW, if you would like to eliminate the context, passing an empty string should work.

    app.use(
        rest.rester(
            {
                context:''
            }
        )
    );

Now you can use a path like '/distributions/:name' without any context.

imrefazekas commented 10 years ago

I checked the code and I'm using underscore.string lib's 'word' function to decompose the URI of the request, that is why it is immune to the '/' string as context and your rest function is called.

jlg7 commented 10 years ago

Hi there,

Thank you for the reply. That makes sense and sounds like I can save myself an explicit slash and use blank then.

Appreciate the evaluation. I was not sure if "//" or "/" should match all the routes defined like /distributions/:name. I am using this in conjunction with static-serving with connect-rest added to the app first and this was stealing the web root's index page.

Thank you,

@jongeho1

imrefazekas commented 10 years ago

Yes, you can use blank context and will work perfectly. :) I hope everything is convenient for you now.

To put the static pages before any rest function would be recommended if I might say so...