miragejs icon indicating copy to clipboard operation
miragejs copied to clipboard

Allow for the Intercepters to be treated as a plugin (Pretender, MSW)

Open cah-brian-gantzler opened this issue 3 years ago • 14 comments

Currently the interceptor is Pretender and it is pretty hardcoded. The intent is to isolate the Interceptor code into its own configuration, then move it to its own package to allow for other interceptors to be specified.

Currently the main entry point to the interceptor code is on the server (the get, put, post, etc methods) and the server is the this then the routes are configured. The goal would be to move these methods to the interceptor code and off the server.

Tasks

  • [x] Move Pretender to its own config. Allow for a way to provide an alternate interceptor. Provide full backward compatibility and make Pretender the default interceptor. https://github.com/miragejs/miragejs/pull/1036
  • [x] Move the pretender code to its own package. (currently in progress see mirage-pretender)
  • [x] Create a package that allows MSW to be used as an interceptor with Mirage. (Currently in progress see mirage-msw)
  • [ ] Remove the Pretender code from MirageJS and require the user to choose the interceptor (Pretender, MSW, or none). This will be a breaking change in MirageJS.
  • [ ] Move the interceptor creation methods (get, put, post, etc) to the interceptor config and make the interceptor config the this when the routes function is run. The Mirage Server will be supplied as a property on the config. For most users this should not be a breaking change, but more advanced uses this could be.

cah-brian-gantzler avatar Apr 23 '22 13:04 cah-brian-gantzler

@samselikoff do you see any glaring issues with this plan? It seems reasonable to me.

IanVS avatar Apr 26 '22 13:04 IanVS

Plan seems good and in fact this was the road we were headed down in https://github.com/miragejs/miragejs/pull/699/files I believe... simplifying the main Mirage server api to be server.handle(request) and then letting folks do whatever they want with it.

Honestly it might be better to remove a hard-coded interceptor altogether and just let Mirage be concerned with turning a request into a response (and making sure it can run in both the browser and node). Then people can use pretender, MSW, even express.

samselikoff avatar Jun 01 '22 15:06 samselikoff

Honestly it might be better to remove a hard-coded interceptor altogether and just let Mirage be concerned with turning a request into a response (and making sure it can run in both the browser and node). Then people can use pretender, MSW, even express.

The hard coded interceptor has already been removed to another repo. I just didnt remove it yet from miragejs as it would be a breaking change. But that is on the roadmap above, the 4th checkbox

cah-brian-gantzler avatar Jun 01 '22 15:06 cah-brian-gantzler

@samselikoff what do you think about making @cah-briangantzler a collaborator? He's doing more work on this package than anyone else at this point, and while I'm happy to keep reviewing and helping out as I can, I don't want to be a bottleneck to the progress that Brian is making.

IanVS avatar Jun 01 '22 20:06 IanVS

Im actually a collaborator on ember-cli-mirage where this repo originated. The work I'm doing there has been spilling over into this one. But I like to have another set of eyes, would prefer to not be the only one 😄

cah-brian-gantzler avatar Jun 01 '22 21:06 cah-brian-gantzler

Of course he can be a collab here I thought he already was! I definitely don't want to be anyone's bottleneck just because I don't have the cycles to work on this anymore 👍

samselikoff avatar Jun 01 '22 21:06 samselikoff

@cah-brian-gantzler is this still active? Is MirageJS still active? I'm using it on a project and running into some issues.

henrymoulton avatar Nov 09 '23 13:11 henrymoulton

It's minimally active, yes. The creator stepped away and a few of us have been trying to keep the lights on.

MSW can indeed be used as an interceptor right now, using https://github.com/miragejs/mirage-msw. It's a bit rough, though, since msw starts up asynchronously, and everything thus far in mirage has been sync. So, to really get it working correctly we'll need to break some APIs I think.

IanVS avatar Nov 09 '23 14:11 IanVS

Yes, I created the initial support for MSW, but IanVS has been taking it to the next step improving it. Thanks IanVS.

cah-brian-gantzler avatar Nov 09 '23 14:11 cah-brian-gantzler

Thanks for the replies both, I'll take a look at moving away from Pretender.

henrymoulton avatar Nov 09 '23 15:11 henrymoulton

I've added a readme to https://github.com/miragejs/mirage-msw, and published 0.1.2. Please open an issue there if you encounter any problems.

IanVS avatar Nov 09 '23 16:11 IanVS

Since there's been some activity on this, I've been working on a mirage-playwright interceptor in a similar vein to support Mirage use in Playwright tests. Should hopefully be open source soon.

nickschot avatar Nov 30 '23 13:11 nickschot