cross domain configuration issues using nginx, sails and upstart-open source projects balderdashy/sails

I’m having cross domain configuration issues using nginx and sails. The problem is that if I get the socket to connect properly via then the RESTful request will fail. If RESTful works the socket will not.




Client is an angular application using "": "0.10.3" and this config io.sails.url = '';.

Server is a sails application with both RESTful request and socket features.

Sails CORS config

module.exports.cors = {
    allRoutes: true,
    origin: '',
    credentials: true,
    headers: 'content-type,Access-Control-Allow-Origin'

Sails socket config

module.exports.socket {
    onConnect: function() {},
    onDisconnect: function() {},
    authorization: false,
    'backwardsCompatibilityFor0.9SocketClients': false,
    grant3rdPartyCookie: true,
    origins: ''

nginx config

Commented out are what I’ve fiddled with in the nginx configuration without much success (also tried the client address instead of *).

server {
    listen 80;

#add_header Access-Control-Allow-Origin *;
    location / {
#       add_header Access-Control-Allow-Origin *;

        proxy_pass http://localhost:1337;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
#        proxy_set_header Access-Control-Allow-Origin *;
        proxy_cache_bypass $http_upgrade;

angularjs service method making the RESTful calls

function query(path, attributes) {

    return $http({
        url: domain + path,
        params: attributes,
        method: "GET",
        widthCredentials: true

In the angular config function

$httpProvider.defaults.useXDomain = true;

It is the current configuration and here are the results I am experiencing.

Browser console output

Resource interpreted as Script but transferred with MIME type text/html: "". – Good

\___/ io.socket connected successfully.
– Good

XMLHttpRequest cannot load No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '' is therefore not allowed access. – Not good


It seems like everything works wonder if I start sails directly using sails lift or node app.js yet when starting it using the upstart script in a .conf file the cross domain issue occurs.

upstart script

description "demo"
author "gillesc"

start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown

respawn limit 5 60

  exec /usr/bin/node /var/www/apps/ > /var/www/apps/ 2>&1
end script