https://github.com/angular/an...假如待請求的接口服務器爲 https://xxx.xxxxxxx.com/api/c...git
項目根目錄
proxy.config.json
target 爲接口服務器github
{ "/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', [])) ); } }