Building SAS Apps Locally

I’ve recently been using Visual Studio to build my SAS Web Apps, which is great as the intellisense will even scan css files to help with code completion.  Perhaps the best feature though is the ability to right click and immediately ‘view in browser’ - which spins up a local web server and avoids the need to constantly modify files on the main dev SAS web server.

However - there are a few things to remember when using this feature to actually connect to SAS.

Same Origin Policy

In simple terms, this is a browser security feature that prevents javascript from connecting to a different server than that from which the page was served.  You’ll know you’re affected if you see something like this in the console:

XMLHttpRequest cannot load https://SASMIDTIER:8080/SASStoredProcess/do. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ’http://localhost:54048’ is therefore not allowed access.
To avoid this (using chrome) simply launch from the command line with that feature disabled - as follows:
“C:Program Files (x86)GoogleChromeApplicationchrome.exe” —user-data-dir=“C:/Chrome dev session” —disable-web-security

hostUrl

Now that we are launching from a local host, the Boemska SAS adapter is unable to automatically determine the mid-tier location.  This info needs to be provided, but not hard coded as we still need the code to work in different environments when it gets promoted.  The following javascript code serves:

  if(location.hostname === ‘localhost’ || location.hostname === ‘127.0.0.1’) {
    var strHostURL = https://SASMIDTIER:8080/’;
  } else {
    strHostURL = null;
  }

  varadapter = new h54s({ hostUrl: strHostURL });

HTML file location

This may not be an issue with your web server / configuration, but something to remember.  I normally keep my my web files organised as follows:
  • ROOT.war
    • JS
    • CSS
    • HTML
    • Images
In order to reference scripts / css / images from my html files, I normally use the ”..” syntax to tell the browser to look ‘up and then down’ a directory, eg as follows:

  <script src=../js/h54s.js></script>

Unfortunately that approach doesn’t work in the web server spun up by VS2015, so I have to temporarily move my html file up into the parent folder and permanently change my references to read as follows:

  <script src=/js/h54s.js></script>

For more information on building Web Apps with SAS you can also check out this guide.  Enjoy!