I am trying to make a angularjs application, independent from a node.js server that is running sailsjs.
I would like to use socket.io for this application and apparently I need to get the socket.io.js file from the server.
In my client I load the js file in my Index.html file using:
<script src="http://localhost:1337/socket.io/socket.io.js"></script>
However sails do not deliver the file because of a handshake error.
Is there anyway to get the file from the server?
Thanks
If you don't need the node.js server, why don't you just copy the socket.io.js file to the web server, and fetch it from there?
The handshake error is explained here: https://github.com/balderdashy/sails/wiki/sockets#500-error-handshake-error-returned-from-socketio-request
You do not have a session with the server so when socket.io.js is included, there is no session cookie for it to use and the handshake fails. You need to make a successful request to the server beforehand that opens a session. This would need to be a CORS request since your server and their server are on different domains. CORS would need to be enabled on the server side using the method explained here: https://github.com/balderdashy/sails-wiki/blob/0.9/config.routes.md#cors-cross-origin-resource-sharing
The easy way is the Javascript Client SDK to communicate with Sails via sockets.
Here is the official project on github: https://github.com/balderdashy/sails.io.js
Related
I am developing an app with PhoneGap (Cordova) + Framework7 and I need to connect to a database. The issue is that it's an hybrid app, which means the www files are local and the app creates an internal server, and so if you try to use AJAX to run a php file it crosses domains, since it'll try to reach for my webserver while it's running it's own server. What can I do?
(I know Cordova has a utility named WebSQL that connects to SQLite, but my database is MySQL, and I think it can only connect to a local db)
(You can't move php to be local because Cordova can't run php files, also it's probably not very secure)
My suggestion is to use Ajax to access your server. (to run the PHP file) You can allow your server URL in environment variables of frontend.
Check for Content-Security-Policy and connect-src in frontend and add your server URL there. Then you will be able to send Ajax to your server.
Hope this helps.
I am using node.js server to consume rest resource from angular js application.
My angular application is running on port 8082 and rest resource available at port 9081. I am able to access rest resource but get CORS exception in developer console.
I find out the solution to get rid of CORS exception. I have used jsonp instead of get method in angular service also got response without any exception, but unable to perform operation on the data return with response.
I come to know that I have to use http-proxy to communicate cross domain applications. If it is right can you please suggest me how can I configure http-proxy in node.js server.
I'm having the same issue as described here Connect from a client to a sails based server where socket continually retries to connect to sails.
I ran sails new from the command line and pulled out the latest sails.io.js file and added to my existing project I'm running sails version 0.11.0 which is a few versions ahead of the person in the question I referenced. Is there something else that could cause this?
Are you sure you took the correct file? The file suggested in that post will not fit to your sails app version as it will fit to 0.10.5 version only. You may take your sails.io.js file from your sails app
mySailsApp/assets/js/dependencies/sails.io.js
also make sure that you specify the server's url that you want to communicate with as it automaticly refers to your localhost.
I want to deploy my AngularJS app which access RESTful web-services onto an aws and I am wondering if I really need a server to serve my AngularJS files.
I can server them as static files or use something like NodeJS but do I really need one?
What are the advantages/dis-advantages of using a server in this scenario?
If your app is small, it's really not a problem if you only access to an API.
But if you want to login via other services where you have for example a public and secret token it's better to work with a server who use cache this datas from your users (maybe it's what your aws is doing).
If you want to access RESTFull Web Services from AWS, you need to put your angularjs files in a server.
The server will give access to resources, if the request is from http protocol. It will deny the request to serve if the protocol is file.
I have a client/server app running on NodeJS with an AngularJS frontend. I want to use the built in debugging features of Webstorm, but it just won't work.
Imagine following scenario:
I have a webstorm project with a client folder and a server folder. I can start the debuggers for the client and the server, and it works. But both sessions are on different ports. So an AJAX request to the server inside the client doesn't work without using CORS and telling AngularJS to use a different server address.
In the production version the client will be published under the server, but for developing there is no need to do this.
Does anyone know how achieve this? Something like: The system should behave like one server, under one URL.
Or is my approach stupid?
Best regards,
Kersten