(function () { "use strict"; angular.module('streamApp').service('apiProxy', function ($http, $window) { //const base = 'https://localhost:4040'; const base = 'https://app.fyli.com'; const authKey = 'fyli_auth'; this.getBaseUrl = function() { return base; } this.GET = function ({ url, params }) { return $http({ url: `${base}/${url}`, params, headers: this.getAuthHeader(), method: 'GET', }); }; this.POST = function ({ url, data, params }) { return $http({ url: `${base}/${url}`, headers: this.getAuthHeader(), data: data, params, method: 'POST' }); }; this.PUT = function ({ url, data, params }) { return $http({ url: `${base}/${url}`, headers: this.getAuthHeader(), data: data, params, method: 'PUT' }); }; this.DELETE = function ({ url, params }) { return $http({ url: `${base}/${url}`, headers: this.getAuthHeader(), params, method: 'DELETE' }); }; this.setToken = function(token) { $window.localStorage.setItem(authKey, token); } this.getAuthHeader = function() { const token = $window.localStorage.getItem(authKey); const header = { Authorization: `Bearer ${token}` } return token ? header : undefined; }; }); }());