Angular 跨域

https://github.com/angular/an...

假如待请求的接口服务器为 https://xxx.xxxxxxx.com/api/c...

项目根目录
proxy.config.json
target 为接口服务器

{
  "/api": {
    "target": "https://xxx.xxx.com/api",
    "changeOrigin": true,
    "secure": false,
    "logLevel": "debug",
    "pathRewrite": {
      "^/api": ""
    }
  }
}
export class AuthenticationService implements AuthService {
    API_URL = '/api/';
    API_ENDPOINT_LOGIN = 'card/Login';

    public login(credential: Credential): Observable<any> {
        // Expecting response from API
        // tslint:disable-next-line:max-line-length
        // {"id":1,"username":"admin","password":"demo","email":"admin@demo.com","accessToken":"access-token-0.022563452858263444","refreshToken":"access-token-0.9348573301432961","roles":["ADMIN"],"pic":"./assets/app/media/img/users/user4.jpg","fullname":"Mark Andre"}
        return this.http.get<AccessData>(this.API_URL + this.API_ENDPOINT_LOGIN + '?' + this.util.urlParam(credential)).pipe(
            map((result: any) => {
                if (result instanceof Array) {
                    return result.pop();
                }
                return result;
            }),
            tap(this.saveAccessData.bind(this)),
            catchError(this.handleError('login', []))
        );
    }
}

Airmusic
228 声望14 粉丝

了解 vue 源码,k8s。熟悉常用前端框架、库、工具:Vue, Angular,React, Webpack,Gulp 等 了解 node, 熟悉 KOA 熟练使用 Git,熟练 Gitflow 等常见开发实践 注重设计细节和用户体验,有较强的审美和自主设计能力...