Category Archives: Development

Ionic – CORS with Live Reload

File this one under ‘lessons learned from hours spent chasing my tail’.

Recently, I’ve been working quite a bit with the Ionic Framework… While I can’t say that I was initially on board for the whole ‘hybrid app’ approach for mobile development, I’ve really grown to love the stack and find it fun to work in. Fun development aside, this isn’t to say that the stack (like any stack) is without its issues – for me currently, it’s the undocumented (or the only-documented-in-a-github-issue) gotchas that can create the largest headaches, as they can often result in an hour or two of tail-chasing.

As you’ve likely gathered from this post’s title, the most recent fun on this front was trying to chase down a CORS issue when testing a tablet application that I am currently writing. In this application, we’ve opted for custom auth headers – adding which caused the CORS issues to rear their ugly head…  In my case, it was specifically issues with Access-Control-Allow-Headers.

“No big deal – Cordova/Phonegap whitelists all domains, so you’re good to go”, right?  As is often the case, “no big deal” can be filed under the category of “famous last words” here…

Not previously known to me, apparently using -l(/livereload) causes a modification to the config.xml at runtime for that build – a modification that removes the ‘*’ whitelisting, which can result in banging your head against CORS issues when interfacing with a REST service during development using livereload…

For the skinny, check out the github issue discussing this – https://github.com/driftyco/ionic-cli/issues/89

Unfortunately, Googling for “Ionic CORS” will provide you with a lot of noise that can result in some tail chasing as you start following suggestions to delete client side default headers or researching server-side solutions to mask the problem… Googling for “livereload CORS” however will take you to some relevant information via Grunt livereload Server discussions.

In the end, it was just easiest to configure my development web server to allow the CORS operations, as I wanted to keep Live Reload capabilities with the least amount of fuss. There are some client side things that you can do (discussed in the linked thread), but as you will find, those are temporary and will need to be done over and over as you develop… I’ve also read some mention of configuring a Grunt proxy server to proxy these requests ‘locally’, but I’ve not been able to investigate that approach, so I can’t really speak to it, though I’d love to get some input on this approach if any readers have any…

Anywhos… I just wanted to put this out there in case “Ionic CORS” led anyone else on a wild goose chase.

Happy Developing!

-Matt

Building Node.js MSI Installer on Windows – Error CNDL0103 cannot find npm.wxs

Recently, while attempting to build a custom release of the Node.js Windows Installer, I encountered a handful of problems and so wanted to detail them here in the case that it might assist another poor soul in saving an hour or two…

First things first – install WIX from here.

Next, if when you attempt to “vcbuild.bat Release msi” or some similar such command and are greeted with the super awesome error message indicating “error CNDL0103: The system cannot find the file > ‘……npm.wxs'” then the build process is unable to locate Heat, which comes with WIX.

For me, the resolution was as simple as ensuring that the Heat.exe (C:Program Files (x86)Windows Installer XML v3.5bin) path was in my Path environmental variable.  Once the duck was in the row, I was able to kick off “vcbuild.bat Release msi” without issue to create my working custom Node.js installer…

Hope this helps!

Edit:  Here is the Discussion Thread on this and my Pull Request to update the installer to include the trailing backslash.

ASP DropDownList DataBind Woes – Invalid SelectedValue Error

Yesterday, as I was plugging away on an ASP WebForms application to add some new features, I encountered an error I had not yet seen.

“SelectedValue which is invalid because it does not exist in the list of items”

Although Googling turned up a lot of results, I could not really find anything that fit the bill as a solution.  I did find a few threads on StackOverflow, though usually these discussions were followed up with additional people asking how the original asker resolved the issue.

For me, it turns out that I was calling the block of code that performed the list population and databind multiple times.  Populating and calling DataBind on this DropDownList multiple times, resulted in the above error.  In the end (after much forehead beating), the solution was an easy one – checking items before attempting to populate and bind to ensure the list was not already initialized.

if (yourDropDownList.Items.Count() == 0) //only populate and bind if not already done…
{
//populate and bind
}

That is it – just checking to ensure the items for the drop down list have not already been populated.  Of course, you really should have your application structured so that this logic is only hit once…. This said, if a complete refactor/rewrite is not in the cards for your application at this time, you can just perform this simple check to work around the exception.

Hope this helps someone!

-Matt