No need to guess the apiOrigin anymore, we redirect now

Fixes #436
This commit is contained in:
Johannes Zellner
2015-07-28 14:03:45 +02:00
parent 4980f79688
commit 733014d8d9
2 changed files with 4 additions and 23 deletions

View File

@@ -30,23 +30,14 @@
// create main application module
var app = angular.module('Application', []);
// FIXME this does not work with custom domains!
function detectApiOrigin() {
var host = window.location.host;
var tmp = host.split('.')[0];
if (tmp.indexOf('-') === -1) return 'https://my-' + host;
else return 'https://my' + tmp.slice(tmp.indexOf('-')) + host.slice(tmp.length);
}
app.controller('Controller', ['$scope', '$http', function ($scope, $http) {
var search = decodeURIComponent(window.location.search).slice(1).split('&').map(function (item) { return item.split('='); }).reduce(function (o, k) { o[k[0]] = k[1]; return o; }, {});
$scope.apiOrigin = detectApiOrigin();
$scope.cloudronName = 'Cloudron';
$scope.referrer = search.referrer || null;
// try to fetch cloudron status
$http.get($scope.apiOrigin + '/api/v1/cloudron/status').success(function(data, status) {
$http.get('/api/v1/cloudron/status').success(function(data, status) {
if (status !== 200 || typeof data !== 'object') return console.error(status, data);
$scope.cloudronName = data.cloudronName;
document.title = $scope.cloudronName + ' App Error';