mirror of
https://github.com/openMF/community-app.git
synced 2026-02-06 18:16:45 +00:00
26 lines
1.1 KiB
JavaScript
26 lines
1.1 KiB
JavaScript
define(['underscore'], {
|
|
FakeServer: function (httpBackend) {
|
|
var getResponseOptions = function (urlMatch, requestData, requestHeaders, response) {
|
|
var options = response;
|
|
if (_.isFunction(response)) {
|
|
options = response.call(null, urlMatch, requestData, requestHeaders);
|
|
}
|
|
return _.defaults(options, {
|
|
returnCode: 200,
|
|
content: {},
|
|
headers: {},
|
|
delay: 0
|
|
});
|
|
};
|
|
|
|
_.each(['get', 'post'], function (method) {
|
|
this[method] = function (urlRegex, response) {
|
|
httpBackend["when" + method.toUpperCase()](urlRegex).respond(function (method, url, data, headers) {
|
|
var responseOptions = getResponseOptions(url.match(urlRegex), data, headers, response);
|
|
httpBackend.responseDelay = responseOptions.delay;
|
|
return [responseOptions.returnCode, responseOptions.content, responseOptions.headers];
|
|
});
|
|
}
|
|
}, this);
|
|
}
|
|
}); |