Combining SailsJS and EmberJS (routing)

271 views Asked by At

I've been using SailsJS for a while now and find it a perfect REST API solution. I'm currently building an app for both Web & Mobile (native) so I need the REST part of SailsJS. I want to build a frontend for my API right now, and I found EmberJS which looks like a promising framework. I've a question about combining those two, they both have their own Routing system, and SailsJS seems to overrule Ember's one.

My guesses would be:

  1. The most easy approach looks like building Sails in a subdirectory eg. /api/ but I think that's not the nicest way to get this fixed.
  2. I could choose one framework for routing and let the other delegating it's routes. For example passing parameters from SailsJS through EmberJS

How can I use those together correctly?

1

There are 1 answers

2
zeppelin On BEST ANSWER

Think of your backand as something you can't control, like a 3rd party API. The reason is that the optimal routing for a user may differ greatly from what's considered to be good API semantics. It's also not easy to share the route declarations, but it's not a good practice anyway.

My advice:

  • Use ember-cli to build the frontend. It's a great tool, you'll enjoy it a lot.
  • Build your Sails-based API in a different repository, using the /api namespace for your API endpoints.
  • Try to follow the JSON API standard as closely as possible. That'll make easier to connect your backend & frontend, as most data libraries (Ember Data for eg.) tries to adhere those standards as well.
  • Watch Luke Melia's excellent guide on lighning fast deployment. It'll be the same concept for you but in Sails intead of Ruby/Rails.

All in all, I think if you'll have a great dev experience if you do roughly what I've outlined above. Happy coding!