安全地访问Web应用程序http.get数据

时间:2016-11-30 14:01:18

标签: javascript php angularjs http-get

我们有一个HTML5应用程序,它使用可通过http.get访问的API。我希望将公开的API URL地址隐藏起来。

将其包含在app.js文件中,可以查看javascript文件。

$http.get('http://myAPIurl.com').success(function(data) {

该应用程序当前存储在具有PHP / MySQL功能的服务器上。

我有没有办法将我的API URL存储在一个PHP文件中(这将隐藏内容),然后在我的app.js文件中包含类似包含文件的内容。

https://jsfiddle.net/4y3cdpn8/

// Ionic Starter App

  // angular.module is a global place for creating, registering and retrieving Angular modules
  // 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
  // the 2nd parameter is an array of 'requires'
  angular.module('starter', ['ionic','ngCordova'])

  .run(function($ionicPlatform) {
    $ionicPlatform.ready(function() {



      if(window.cordova && window.cordova.plugins.Keyboard) {
        // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
        // for form inputs)
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

        // Don't remove this line unless you know what you are doing. It stops the viewport
        // from snapping when text inputs are focused. Ionic handles this internally for
        // a much nicer keyboard experience.
        cordova.plugins.Keyboard.disableScroll(true);
      }
      if(window.StatusBar) {
        StatusBar.styleDefault();
      }
    });
  })

  .config(function($stateProvider, $urlRouterProvider) {

    $stateProvider
      .state('tabs', {
        url: '/tab',
        cache: false,
        abstract: true,
        templateUrl: 'templates/tabs.html'
      })
      .state('tabs.home', {
        url: '/home',
        cache: false,
        views: {
          'home-tab' : {
           templateUrl: 'templates/home.html'
          }
        }
      })
      .state('tabs.list', {
        url: '/list',
        cache: false,
        views: {
          'list-tab' : {
           templateUrl: 'templates/list.html',
           controller: 'ListController'
          }
        }
      })

        // if none of the above states are matched, use this as the fallback
        $urlRouterProvider.otherwise('/tab/home');

  })

  .controller('ListController', ['$scope', '$http', '$state','$stateParams', '$window', '$location', function($scope, $http, $state, $stateParams, $window, $location) {

            $scope.query = '';         
            $scope.getOrders= function(query){

                   $http.get('http://myAPIurl.com').success(function(data) {
                    $scope.orders = data;

                   })
            }


                $state.go('tabs.home');
            }

  }]);

0 个答案:

没有答案