Node support tracking issue
See original GitHub issueThis issue is to track the work needed for making Mirage’s server runnable in Node. I want to write up our current thinking so that we can start to solicit feedback.
Mirage works by intercepting browser calls to fetch
and XMLHttpRequst
and returning a mocked HTTP response. For Node environments the approach we are taking is a bit different. Instead of intercepting all outgoing network requests from Node we will be providing a lower level APIs that allow you generate Mirage responses in user land.
For example, there will be a server.handleRequest({ method: 'GET', path: '/articles', ... })
function to generate a Mirage response for a GET /articles
.
The reason for this approach is that it allows you to use a Mirage response however you see fit. It can be served from an express server or used with a node mocking library like nock. Because the use cases for running Mirage in node are much more diverse than the browser, we feel providing these lower level APIs is a good first step.
The first APIs we want to add to server
:
canHandle(request): boolean
handleRequest(request): response
At this time we are unsure about the shape of the request/response objects. We will most likely look to current Mirage/Pretender and use these objects as a starting point.
Any feedback would be greatly appreciated! Thanks
Issue Analytics
- State:
- Created 4 years ago
- Reactions:8
- Comments:9 (5 by maintainers)
Top GitHub Comments
What about using Node’s own request object?
I’m just suggesting this because for instance
express
extends that object, whilekoa
uses it directly. By supporting it we can pretty much guarantee that is going to work anywhere, don’t we?Check out this
express
docs page: https://expressjs.com/en/api.html#reqJust checked, it does work, but when using typescript you cant import and use only the orm without the server. i noticed more issues with the types. might open a pr if i get the chance… anyway, thanks for the quick reply!