jakerella / jquery-mockjax

The jQuery Mockjax Plugin provides a simple and extremely flexible interface for mocking or simulating ajax requests and responses
Other
2.11k stars 375 forks source link

Dynamically Generating Mock Definitions #359

Open Vladzimir opened 4 years ago

Vladzimir commented 4 years ago

$.mockjax(function(settings) {

// settings.url might be: "/restful/" such as "/restful/user"

var service = settings.url.match(/\/restful\/(.*)$/); if ( service ) { return { proxy: "/mocks/" + service[1] + ".json" }; } // If you get here, there was no url match return; });

Using this method fails to redirect POST data to proxy url Have to use crutches

proxyType: settings.type, data: settings.data, headers: settings.headers, contentType: settings.contentType

jakerella commented 4 years ago

Hmm... well, that's not a valid regex, but maybe you've already escaped it and GitHub just isn't checking properly?

This: settings.url.match(//restful/(.*)$/); should probably be: settings.url.match(/\/restful\/(.*)$/);

I'll have to write a little test to see if I can replicate this.