sane / sane

Sane Stack - A Sails and Ember cli to get you kickstarted with app development
http://sanestack.com/
MIT License
474 stars 44 forks source link

Websocket is not working #165

Open hashg opened 9 years ago

hashg commented 9 years ago

I was looking for Emberjs & Sails adapter, I found out this awesome project. This are the version

sane       : 0.0.24
Sails      : 0.11.0 
ember-cli  : 0.2.7
Ember      : 1.12.0
Ember Data : 1.0.0-beta.18

Setting up was a breeze. I created user and able to add new records easily.

sane new -d disk  emberSailjs
sane generate resource user name:string info:string 
ember install ember-data-sails

//client/app/adapters/application.js

import DS from 'ember-data';
//import SailsSocketAdapter from 'ember-data-sails/adapters/sails-socket';
//import SailsRESTAdapter from 'ember-data-sails/adapters/sails-socket';

//export default SailsSocketAdapter.extend({
//export default SailsRESTAdapter.extend({
export default DS.RESTAdapter.extend({
  coalesceFindRequests: true,
  namespace:            'api/v1',
  useCSRF:              true,
  defaultSerializer:    '-rest',
});

//client/app/controller/user.js

var user = store.createRecord('user', {
  name: 'Test'+rand,
  region: 'Regsion'+rand
});

user.save();

The issue is some how I am not able to see the magic of websocket, automatically updating on the other clients when I create a record on one of the clients.

I tried flipping the adapter to SailsSocketAdapter, SailsRESTAdapter. Both lead to this error in console.

Uncaught SyntaxError: Unexpected token <  (__getcookie:1)

Failing at first line of index.html

<h1>Welcome to your backend!<h1><br>
<h2>When deploying replace this with your great ember app. In the meantime access your api at 'api/v1/models' and your ember app at localhost:4200.</h1>

It is trying to read the server index.html from this code. //sails.io.js

    function jsonp(opts, cb) {
      opts = opts || {};

      if (typeof window === 'undefined') {
        // TODO: refactor node usage to live in here
        return cb();
      }

      var scriptEl = document.createElement('script');
      window._sailsIoJSConnect = function(response) {
        scriptEl.parentNode.removeChild(scriptEl);

        cb(response);
      };
      scriptEl.src = opts.url;
      document.getElementsByTagName('head')[0].appendChild(scriptEl); //THIS LINE//

    }

@Globegitter / @huafu Am I doing anything wrong here? If you can point me to repo which has this working that also would help.

huafu commented 9 years ago

@hashg you must use the SailsSocketAdapter and in the sails part setup the config so that it works with.... sockets of course. badly I have not much time right now to check this but looking at your error it sounds like there is something misconfigured in the API part.

IanVS commented 9 years ago

@hashg is this still a problem or can we close the issue?

hashg commented 9 years ago

@IanVS It is still a problem. I might be approaching it the wrong way. If you can point me to working sample, I can verify and close the issue.

IanVS commented 9 years ago

I haven't used sockets myself, but I think you can look at https://github.com/jamemackson/example-sane-realtime for an example.

HERRKIN commented 9 years ago

I have the same problem it seems sails.io.js is loaded but it wont connect, I never get the sails logo on the console (so its not connected).

if i use sails.io.js from bower it connects but it wont work either its so weird

HERRKIN commented 9 years ago

I created another issue because it is not specifically to sockets but to csrf tokens, this is the reason why the adapter doesn't work https://github.com/sane/sane/issues/201