Question

Has anyone tried to use sails as ember's backend API? How would you go about it? Is there an example available? Since Sails has a different format in its built-in blueprints, is it better to make sails rest json format confirm to what ember expects or the other way around?

Thanks!

Edit

So there are two approaches:

  1. change the sails format, maybe with: CRUD blueprint overriding in sails.js

  2. change what ember expects: http://discuss.emberjs.com/t/sails-js-as-the-backend/5233

Was it helpful?

Solution 2

I can't speak for the "change what Ember expects" option, but I can say that this is precisely what blueprint overrides in Sails were invented for. This would be a perfectly reasonable way to make your app Ember-compatible.

Also keep in mind that all of the CRUD blueprints use the res.ok() response to actually send data down to the client; if you like, you can just override that with your own api/responses/ok.js, perhaps using req.url to determine the resource that was being requested, and use that to wrap your JSON object in the manner that Ember expects.

OTHER TIPS

There is a project called Sane Stack that uses a Sails blueprint to generate the appropriate setup for Ember and Sails, as well as provides a generator for creating resources in Ember and Sails at the same time.

QUICKSTART

npm install -g sails sane-cli

sane new project --docker creates project with sails-disk and Docker. For production databases see Options.

sane generate resource user name:string age:number to generate a new API on the backend and models on the frontend

sane up to start the sails server on localhost:1337 as well as the ember dev server on localhost:4200.

To work on your frontend-app you work as you would normally do with ember-cli on localhost:4200.

You are now good to go.

Note: If you use Docker, make sure you have fig installed. On Mac or Windows also boot2docker and for Linux see: https://docs.docker.com/installation/ubuntulinux/

I just put up a few blueprint overrides that can be used as a starting point for using Sails as an Ember Data backend: https://github.com/mphasize/sails-ember-blueprints

Please let me know if you find a bug or have some suggestions for improvements!

Haven't used ember in a few months, but the default blueprints responses are not compatible with ember-data.

Ember seems to be trying to conform to the jsonapi spec.

Sails default blueprint responses do not.

That being said, it would be pretty easy to roll your own responses with sails.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top