coderly / teamplaybook-ember

0 stars 0 forks source link

Implement interface separation between general and organization-specific routes #8

Closed begedin closed 9 years ago

begedin commented 9 years ago

NOTE: This branches off of #7 so it contains changes from there as well.

This is an attempt to create interface separation between general and organization-specific routes. It works, sort of, but I don't like the way I achieved it. I pushed the changes up here so we can discuss ideas for potential alternatives.

Assumption

The following doesn't work:

export default Router.map(function () {
  this.route('login');
  this.resource('organization', { path: '/' });
  this.route('some_general_route', { path: '/' });
});

That is, it works, but if we want to access the general route, it will still attempt to access the organization resource and try to load a model.

Basically, I don't think we can have routing to two different things on the same route URL. To Ember, domain.com/ and subdomain.domain.com are the same resource/route.

Solution

The currently implemented solution (which I really dislike) is the following:

In my opinion, the ideal solution and one we should spend at least some time exploring would be to modify the default ember router so it works for our specific case of having two resources ("organization" and "general") under the same path "/". If we only ever access links via the resource.route reference and not via the path reference, I don't think having them on the same URL path would be an issue.

I'm not sure if that solution is possible, though.

venkatd commented 9 years ago

It may best to check window.location.host to add this check at a lower level.

http://stackoverflow.com/questions/18262215/ember-js-rails-and-wildcard-subdomains

We can have two routers OrganizationRouter and DefaultRouter. Then we can export the proper one depending on this check. Thoughts?

begedin commented 9 years ago

@venkatd: That seems like the most straightforward approach. I tried looking into actually customizing the default router (.reopenClass, .extend), but the actual routing is highly encapsulated so I don't think it was intended for us to customize it.

begedin commented 9 years ago

@venkatd For an update, I ended up doing something similar to what you suggested. The only thing is, we don't export the Router in router.js. We export the result of a Router.map(callback) call. Since some routes will be common to both sides of the app (login route, for instance), I ended up doing a logical flag check within the Router.map callback and it's at that point that the route definition splits.

Because of that and the fact that ember-cli-subdomain only works as something you inject into various parts of the app, I had to implement my own url-info library and abandon the ember-cli-subdomain add-on. Looking at the code of the add-on, though, the logic I'm using is nearly identical. It's not actually something very complex.

begedin commented 9 years ago

I believe this is now at a point where it should be mergable. Next up, we either start hooking this up to the actual API, or I can start working on the actual interface, depending on which comes sooner.