Skip to content
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

Wildcard routes? #28

Closed
darrendb opened this issue Mar 27, 2014 · 1 comment
Closed

Wildcard routes? #28

darrendb opened this issue Mar 27, 2014 · 1 comment

Comments

@darrendb
Copy link

I'm using compoundjs to serve a RESTful api. I'm using an 'api' namespace to handle the REST calls like this:

    map.namespace('api', function (api) {
        api.get('targets',          'targets#index');
        api.get('targets/:id',      'targets#show');
        api.post('targets',         'targets#create');
        api.put('targets/:id',      'targets#update');
        api.delete('targets/:id',   'targets#destroy');
    });

On the client I am trying to use a simple backbone single-page app using pushState=true.

I'm having trouble figuring out the routing to keep node/express/compound from getting involved with anything other than the api. I've heard some mention of a wildcard route like '*' used in low-level express, maybe something like this:

app.get("*", function(req, res){
  res.sendfile('index.html');
});

When I tried doing something like map.get('', ...) and checked the route table with 'compound routes' it seemed that the '' was being treated as a string literal and it was trying to map a path like '/*', rather than recognizing it as a wildcard.

Is there some equivalent in railway-routes/compoundjs for this? Ultimately I want to preserve a request such as '/targets' or '/targets/3', server should just ignore or serve index.html and let backbone read the '/targets/3' and handle it with its client-side routing. I'm also concerned that using something like "res.sendfile('index.html')" would change the url before the client see's it, stripping the 'targets/3' before backbone can respond to it.

I found some similar Q&A on Stack Overflow but nothing that seemed to be specific to compoundjs or railway-routes.

Any suggestions, or documentation links would be greatly appreciated. Thanks!

@1602
Copy link
Owner

1602 commented Mar 27, 2014

was being treated as a string literal and it was trying to map a path like '/*', rather than recognizing it as a wildcard.

not true.

if you specify

map.all('admin/*', 'ctl#test');

or

map.all('*', 'ctl#test');

depending on your needs you will be able to get all requests to posts.

@1602 1602 closed this as completed Mar 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants