由于一些基础设施的更改(即服务器和VPN),有时我希望以脱机模式运行我们的应用程序。我已经能够用ngMockE2E实现这一点,但是它似乎是一种全部或根本不存在的方法,这意味着您必须显式地将每个HTTP请求从应用程序中设置出来。
有没有一种方法可以让它假定,除非您已经显式地设置了要处理的路由/url,否则它将自动调用一个通用的passThrough()操作?
目前,我正在这样做:
noSrvc = $location.search().hasOwnProperty 'nosrvc'
#
# templates
#
$httpBackend.whenGET /(\.htm|\.html)$/
.passThrough();
#
# session
#
rqst = $httpBackend.whenGET /(api\/users\/current)$/
if !noSrvc then rqst.passThrough() else rqst.respond {"user":{
# doing something similar for every single service call in the app... gets tedious after about 3-4我所读到的关于这个主题的大部分内容都是关于单元测试的,除非另有说明,否则没有真正解决隐含的传递问题。
发布于 2015-10-20 21:25:48
这就是我用来做白名单的配方
app.run(function ($httpBackend) {
// mocked requests, should come first
$httpBackend.when('GET', 'mock').respond(200, {});
// whitelisted real requests, should come last
angular.forEach(['GET', 'DELETE', 'JSONP', 'HEAD', 'PUT', 'POST', 'PATCH'], function (method) {
$httpBackend.when(method).passThrough();
});
});我敢肯定优先权在这里很重要。
https://stackoverflow.com/questions/33245499
复制相似问题