To avoid the added complexity, can we change this to: 
```javascript
var BASE_URL = location.protocol + '//' + location.hostname;
```