Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sails.js and Ember.js integration

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

like image 659
Ofri Avatar asked May 13 '14 18:05

Ofri


3 Answers

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/

like image 178
jhliberty Avatar answered Nov 15 '22 12:11

jhliberty


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.

like image 36
sgress454 Avatar answered Nov 15 '22 11:11

sgress454


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!

like image 40
mphasize Avatar answered Nov 15 '22 12:11

mphasize