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', []))
);
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。