balderdashy/angularSails

Q. How to get it work when frontend runnuing on a different port ?

Opened this issue · 5 comments

My backend and frontend is running on separate port and there is no guide about this.

The simplest way looks like this:

<script src=“sails.io.js></script> <script> io.sails.url = “http://someurl:1234”; </script> <script src=“ngsails.io.js”></script>

On Sep 21, 2014, at 12:33 PM, Sabbir Ahmed notifications@github.com wrote:

My backend and frontend is running on separate port and there is no guide about this.


Reply to this email directly or view it on GitHub.

Thanks @robwormald

I have created file a called sail.io.configs.js which loads after sails.io.js and configured it like bellow :

io.sails.url = "http://localhost:1337";
io.sails.useCORSRouteToGetCookie = false;


(function () {
  function checkScriptEnv(urlRegexp) {
    if (
      typeof window !== 'object' ||
      typeof window.document !== 'object' ||
      typeof window.document.getElementsByTagName !== 'function'
    ) {
      return '';
    }
    var allScriptsCurrentlyInDOM = window.document.getElementsByTagName('script');
    var thisScript = allScriptsCurrentlyInDOM[allScriptsCurrentlyInDOM.length - 1];
    return thisScript.src.match(urlRegexp);
  }
  var env = checkScriptEnv(/production/g);
  io.sails.environment = env ? 'production' : 'development';

})();

Reasons : My front-end production files url is not same and I would like it to be more configurable.

Thoughts : It would be great if there was separate file like this in the bower package for configurations which will load right after sails.io.js and we can get rid of environment detection at sails.io.js. Let me know your thoughts.

The latest builds (see the resource branch) actually drop the sails.io.js requirement in favor of a more angular-ly approach:

app.config(function($sailsConnection){
$sailsConnection.baseUrl = “http://localhost:1337”;
});

which you could easily break out into a separate file (or multiple files) for cleaner usage.

R

On Sep 22, 2014, at 2:17 PM, Sabbir Ahmed notifications@github.com wrote:

Thanks @robwormald

I have created file a called sail.io.configs.js which loads after sails.io.js and configured it like bellow :

io.sails.url = "http://localhost:1337";
io.sails.useCORSRouteToGetCookie = false;

(function () {
function checkScriptEnv(urlRegexp) {
if (
typeof window !== 'object' ||
typeof window.document !== 'object' ||
typeof window.document.getElementsByTagName !== 'function'
) {
return '';
}
var allScriptsCurrentlyInDOM = window.document.getElementsByTagName('script');
var thisScript = allScriptsCurrentlyInDOM[allScriptsCurrentlyInDOM.length - 1];
return thisScript.src.match(urlRegexp);
}
var env = checkScriptEnv(/production/g);
io.sails.environment = env ? 'production' : 'development';

})();
Reasons : My front-end production files url is not same and I would like to be more configurable.

Thoughts : It would be great if there was separate file like this in the bower package for configurations which will load right after sails.io.js and we can get rid of environment detection at sails.io.js. Let me know your thoughts.


Reply to this email directly or view it on GitHub.

The approach mentioned above has an inconsistent behavior, where it occasionally fails to set the server URL before the connection is made automatically. I've noticed it is quite common for it to fail on IOS devices with Safari/Chrome.

I described my approach on how to deal with the problem I mentioned, on this related issue:
https://github.com/balderdashy/sails.io.js/issues/12