I am having problems setting up cross domains using nginx and sails. The problem is that if I correctly connect the socket through http://domain-server.com/socket.io/ then the RESTful request will not be executed. If RESTful works, the socket will not.
Customization
Customer http://domain.com
Server http://server-domain.com
The client is the angular application "sails.io.js": "0.10.3" and this configuration io.sails.url = 'http://domain-server.com'; .
Server is a sails application with RESTful request functions and sockets.
Sails CORS Configuration
module.exports.cors = { allRoutes: true, origin: 'http://domain.com', credentials: true, methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD', headers: 'content-type,Access-Control-Allow-Origin' };
Sails Socket Configuration
module.exports.socket { onConnect: function() {}, onDisconnect: function() {}, authorization: false, 'backwardsCompatibilityFor0.9SocketClients': false, grant3rdPartyCookie: true, origins: 'http://domain.com' };
Nginx configuration
Commented on what I was looking for in nginx configuration without much success (also tried client address instead of *).
server { listen 80; server_name domain-server.com;
angularjs method calling RESTful calls
function query(path, attributes) { return $http({ url: domain + path, params: attributes, method: "GET", widthCredentials: true }); }
In angular config function
$httpProvider.defaults.useXDomain = true;
This is the current configuration, and here are the results that I am experiencing.
Browser Console Output
Resource interpreted as Script but transferred with MIME type text/html: "http://domain-server.com/__getcookie". - Good
|>
\___/ sails.io.js:200 io.socket connected successfully. - Good
XMLHttpRequest cannot load http://domain-server.com/login?password=test&username=test. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://domain.com' is therefore not allowed access. - Not good
UPDATE
Everything seems to work if I start sails directly using sails lift or node app.js , but when running with upstart script in the .conf file there is a cross domain problem.
upstart script
#!upstart description "demo" author "gillesc" start on (local-filesystems and net-device-up IFACE=eth0) stop on shutdown respawn respawn limit 5 60 script exec /usr/bin/node /var/www/apps/domain-server.com/app.js > /var/www/apps/domain-server.com/server.log 2>&1 end script