Skip to content

Commit

Permalink
WA代码:增加统一的后端接口服务
Browse files Browse the repository at this point in the history
  • Loading branch information
amio committed Apr 1, 2014
1 parent 776c030 commit 70c3058
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<!-- build:js scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script src="scripts/services/edit.js"></script>
<script src="scripts/services/backend.js"></script>
<script src="scripts/services/login.js"></script>
<script src="scripts/services/notify.js"></script>
<script src="scripts/services/formdata.js"></script>
Expand Down
15 changes: 15 additions & 0 deletions app/scripts/services/backend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

angular.module('toHELL')
.factory('backendService', [ '$http', '$location', function ($http, $location) {

var isBeta = /(beta|:9999)/.test(window.location.href);

return {
host: 'http://wxddb1.qa.nt.ctripcorp.com/',
pkgHost: isBeta ? 'http://wxddb1.qa.nt.ctripcorp.com/betapackages/'
: 'http://wxddb1.qa.nt.ctripcorp.com/packages/',
apiHost: isBeta ? 'http://wxddb1.qa.nt.ctripcorp.com/tohellbeta/'
: 'http://wxddb1.qa.nt.ctripcorp.com/tohell/'
}
}]);
7 changes: 4 additions & 3 deletions app/scripts/services/login.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

angular.module('toHELL').factory('loginService', [ '$http', 'GLOBAL', '$location', function ($http, GLOBAL, $location) {
angular.module('toHELL')
.factory('loginService', [ '$http', '$location', 'backendService', function ($http, $location, backend) {

var loggedInUser;

Expand All @@ -21,7 +22,7 @@ angular.module('toHELL').factory('loginService', [ '$http', 'GLOBAL', '$location
account.passwd = V.Security.md5(account.passwd);

// Login
$http.post(GLOBAL.apiHost + 'login/', account)
$http.post(backend.apiHost + 'login/', account)
.success(function (res) {
switch (res.status) {

Expand All @@ -34,7 +35,7 @@ angular.module('toHELL').factory('loginService', [ '$http', 'GLOBAL', '$location

default:
// Else
var errDesc = GLOBAL.errDesc[res.error_code] || '未知错误';
var errDesc = backend.errDesc[res.error_code] || '未知错误';
console.log('Login Error: ', errDesc, res);
errCallback && errCallback(res);
}
Expand Down

0 comments on commit 70c3058

Please sign in to comment.