1

I have the following configuration in my angular nodejs app minified javascript file

   // Constants
    .constant('config', {
        appName: 'My App',
        appVersion: 1.0,
        apiUrl: "someAPI"
});

But when the requests are made from this client as

http:/server-hosting-client/someAPI/api/ Failed to load resource: the server responded with a status of 404 (Not found)

I want the requests to be sent as

 http://someAPI/api/

Where is this appending its own host name from?

Here is an example client request

.controller('HeaderCtrl', ['$scope', '$http', '$location', 'config', function($scope, $http, $location, config) {    
    $scope.appName = config.appName;
    $scope.selected = undefined;
    $http.get(
       config.apiUrl+'/api/', {
            'withCredentials' : true
        }).success(function(data) {



        });

Note that I am running the app from the dist folder

/dist/ npm start
4

1 回答 1

1

config.apiUrl需要包含协议:

// Constants
.constant('config', {
   appName: 'My App',
   appVersion: 1.0,
   apiUrl: "http://someAPI"
});

否则,API url 被假定为当前主机名的子路径。

于 2017-01-12T14:21:29.700 回答