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

Multiple Prefixes Support #13

Open
scott-wyatt opened this issue Sep 17, 2018 · 4 comments
Open

Multiple Prefixes Support #13

scott-wyatt opened this issue Sep 17, 2018 · 4 comments
Labels
enhancement New feature or request

Comments

@scott-wyatt
Copy link
Contributor

scott-wyatt commented Sep 17, 2018

Issue Description

Feature: Support Multiple Prefixes by providing a handler version.

Concept

{
  // ...
  '/example/test': {
    'GET': {
       versions: { 
           'ExampleController.get': {
              config: {
                 prefix: 'prefix.one'
                 pre: [ 'ExamplePolicy.get' ]
              }
          },
          'ExampleController.getTwo': {
                config: {
                 prefix: 'prefix.two'
                 pre: [ 'ExamplePolicy.get' ]
              }
           }
        }
    },
    'POST': {
      handler: 'ExampleController.post',
      config: {
        prefix: '/api/v2'
        pre: [ 'ExamplePolicy.post' ]
      }
    }
  }
  // ...
}
@jaumard
Copy link
Member

jaumard commented Oct 23, 2019

is this live ? because PR was merged ^^

@scott-wyatt
Copy link
Contributor Author

scott-wyatt commented Oct 23, 2019 via email

@jaumard
Copy link
Member

jaumard commented Oct 23, 2019

I think the router should pre-rebuild the URL from the config to have /api/v1/whatever /api/v2/whatever. And then go to splitRoute that should do his job just fine ^^

Another way to support this is with the default prefix, for example support prefix: '/api/v1 and prefix: '[/api/v1, /api/v2] like this globally all endpoint are available for both endpoints.

Later on the controller something like req.version will give v1 or v2 and you can manage that here. It's another way of seeing version support :) but maybe less open to fine tuning

@scott-wyatt
Copy link
Contributor Author

So the first part, that's kind of already possible:
you can make the route just

/api/v1/<route>: {
  GET: 'myController.<myMethod>',
  config: {
     app: {
        version: 1
     }
   }
},
/api/v2/<route>: {
  GET: 'myController.<myMethod>',
  config: {
     app: {
        version: 2
     }
   }
}

And then get the app.version in the controller from the match on the webserver.

The second part: auto making everything to have a 2nd prefix would kill some of my apps that already have 800 routes lol.

Right now, there are at least 5 different ways to configure the router, which is kind of crazy, which is what the function splitRoute handles.

The other thing I've been thinking a lot about is route scope, and how we could make routes scoped for things like oAuth standards etc. Authentication is something almost every app needs, and there's no real good support for it in fabrix unless you want to use spool-passport and spool-permissions, even then, I almost always rewrite that logic in my own apps because they are too general for what I want to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants