janpantel / angular-sails

An angular module for using the sails socket.io api
MIT License
307 stars 56 forks source link

Cross domain Standalone app issues #34

Closed msimonc closed 9 years ago

msimonc commented 10 years ago

I set up duplicate Sails servers. $sails works fine when Angular app is served from 1337. Then specifying a sockets server in app.config():

$sailsProvider.url = 'http://localhost:1338';

on 1338 gives

verbose: A socket.io client (PQjE7nvxWrwUrMDc50Dg) connected successfully!

but socket data is still comes from 1337

verbose: websocket writing 6:::1+[{"body":{"data":[{"user":{"username":"abc","email":"abc@123...

even when I put the full url in the get()

$sails.get( 'http://localhost:1338' + url, function (models) {

and turn off session auth on 1338

module.exports.policies = {
   'myController': true
}

Thanks,

janpantel commented 10 years ago

Check this please: https://github.com/janpantel/angular-sails/issues/25

msimonc commented 10 years ago

That project doesn't use $sailsProvider and is a server that serves the ng app, db and socket connections between the two. Continued thanks,

TheSharpieOne commented 9 years ago

@msimonc can you use chrome dev tools to look to see where the connection is going? You should be able to see two requests. An initial request and the request that ends up getting upgraded to a socket connection.

It should look something like this: image

Then, check the URLs (by hovering over) to make sure its going to the right place.

psi-4ward commented 9 years ago

I had a similar issue while serving the app through another Domain/Port. Seems you have to configure io.sails.url globally cause of its autoConnect feautre.

Working:

io.sails.url = 'http://localhost:1337';

Not working:

app.config(function($sailsProvider) {
  $sailsProvider.url = 'http://localhost:1337';
});
Martinsos commented 9 years ago

I have problem with same origin I believe: it has no effect to set $sailsProvider.url in angular config because io.sails already does autoConnect, immediately after sails.io.js script is loaded. Is there any way to solve this? I tried disabling auto connection using io.sails.autoConnect = false, but there is no way to enable connection later, in angular config.

psi-4ward commented 9 years ago

Ill hope my pull which im preparing next days will solve this issue. Its already open, please try https://github.com/psi-4ward/angular-sails/blob/refactor-psi/src/service/angular-sails.js

note socket.io-client is not included here

Martinsos commented 9 years ago

Awesome @psi-4ward! Looking forward to it getting integrated

JetFault commented 9 years ago

I wasn't able to use auto-connect (mainly because I wanted to manually connect once you login), so added the connect option to my own fork (which has request/response transforms as well).

My fork started out as a refactor but I've been adding features and haven't had time to PR back in here.

Relevant line that does the connecting: https://github.com/JetFault/angular-sails/blob/master/src/service/angular-sails.js#L114

Its still for Sails v0.10, but I'm planning on upgrading to v0.11 in the coming 2 days.

TheSharpieOne commented 9 years ago

We've been working on some refactoring and updating and getting much needed tests. I'll take a look at your branch and see what we can bring in. I was contemplating on a more or less rewrite for v2 and getting rid of the sails.io.js dependency as it limits our interaction with socket.io by abstracting it. We can create our own abstracts to allow for more functionally and abilities.

TheSharpieOne commented 9 years ago

After looking at your branch, you are using the connect and disconnect functions you made to create a new socket connection using the 'raw' socket.io connect vs the ~new-ish~ io.sails.connect that is part of sails.io.js. The io.sails.connect is one of the problems that I was talking about before (and why we should remove the dependency of sails.io.js), it abstracts the 'meat and potatoes' away (so to speak), limiting the options we can pass to it. sails.io.js ends up doing its own thing. We could do some tricky things to work with it, but similar to what you did (and funny enough, what angularSails did), we probably would work directly with socket.io and create our own "SailSocket".

JetFault commented 9 years ago

@TheSharpieOne I believe this is what balderdashy/angularSails did.

I don't know how I feel about it. Whenever there would be a change there we would have to manually add it into here. Also, the raw socket.io socket can be accessed using _raw if you do need to access the socket.

But I do agree that I have faced a bunch of issues integrating the sails.io.js that I had to make own fork to work better with angular :/

TheSharpieOne commented 9 years ago

Yeah, we ended up having to use the socket._raw to get at the .once() method as sails.io.js doesn't expose it or abstract it. Seeing how balderdash makes both and ended up implementing it in both projects, its probably not a bad idea for this project to do it as well. As for keeping up with the changes, sails.io.js is constantly changing and often times only works with the latest version of sailsjs. I think we can better ensure backwards compatibility and even implement new features that work with sailjs.