admin管理员组文章数量:1389762
I am working on a angular app & fetching data from back end API endpoint with the get / post method of HTTP module. Recently I have checked a angular app where they are hiding API real endpoint & replacing with some other end point.
for e.g
Real Endpoint:- 'http://192.168.1.192:8080/restaurant/getUserData/'
Replaced Endpoint:- 'http://192.168.1.192:8080/restaurant/getServerData'
also I can see the replaced endpoint in the 'network' tab of 'Developer Tool'.
I know that this can be achieved by using interceptors concept. but I never worked with HTTP interceptor. if any one know how to achieve the same please suggest.
I am working on a angular app & fetching data from back end API endpoint with the get / post method of HTTP module. Recently I have checked a angular app where they are hiding API real endpoint & replacing with some other end point.
for e.g
Real Endpoint:- 'http://192.168.1.192:8080/restaurant/getUserData/'
Replaced Endpoint:- 'http://192.168.1.192:8080/restaurant/getServerData'
also I can see the replaced endpoint in the 'network' tab of 'Developer Tool'.
I know that this can be achieved by using interceptors concept. but I never worked with HTTP interceptor. if any one know how to achieve the same please suggest.
Share Improve this question edited Dec 18, 2019 at 10:43 Lakhan Khandelwal asked Dec 18, 2019 at 10:40 Lakhan KhandelwalLakhan Khandelwal 632 silver badges17 bronze badges 3- Please refer to angular.io/guide/http#http-interceptors – uajov6 Commented Dec 18, 2019 at 10:42
- http interceptors are not used for this purpose generally. – Mridul Commented Dec 18, 2019 at 10:45
- I would suggest you look at proxy angular.io/guide/build#proxying-to-a-backend-server – Bojan Kogoj Commented Dec 18, 2019 at 10:49
2 Answers
Reset to default 4@Injectable()
export class Interceptor implements HttpInterceptor {
constructor() { }
const redirectRequest = request.clone({ url: 'http://192.168.1.192:8080/restaurant/getServerData', method: "get" });
return next.handle(redirectRequest);
}
@Injectable()
export class Interceptor implements HttpInterceptor {
constructor() { }
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const dupReq = req.clone({ url: 'mynewurl.' });
return next.handle(dupReq);
}
}
本文标签: javascripthow to change HTTP Request URL using angular 6 interceptorStack Overflow
版权声明:本文标题:javascript - how to change HTTP Request URL using angular 6 interceptor - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744675132a2619063.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论