Created
March 4, 2014 09:30
-
-
Save kennethlynne/9343149 to your computer and use it in GitHub Desktop.
mock-backend fake delay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('yourApp') | |
.config(function ($httpProvider, Config) { | |
if(!Config.useMocks) return; | |
$httpProvider.interceptors.push(function ($q, $timeout, Config, $log) { | |
return { | |
'request': function (config) { | |
$log.log('Requesting ' + config.url, config); | |
return config; | |
}, | |
'response': function (response) { | |
var deferred = $q.defer(); | |
if(response.config.url.indexOf(Config.view_dir) == 0) return response; //Let through views immideately | |
//Fake delay on response from APIs and other urls | |
$log.log('Delaying response with ' + Config.API.fakeDelay + 'ms'); | |
$timeout(function () { | |
deferred.resolve(response); | |
}, Config.API.fakeDelay); | |
return deferred.promise; | |
} | |
} | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment