thefrontside / simulacrum

A simulation platform for use during testing, during development and for high-fidelity application previews
85 stars 14 forks source link

✨Add ability to extend the Github API Router with custom middleware #258

Closed cowboyd closed 1 year ago

cowboyd commented 1 year ago

Motivation

Our implementation of the GitHub API is incomplete which is not suprising given that it is huge. However this poses a problem for someone using the API simulator. What if the API is missing something that they need? Their options are to submit a PR to this repo, or to just start the things they need on another port. This is doable, but it means that they have to manage two servers, and also that the simulation does not appear to be hosted at the same origin. That's an unecessary burden. We need a way to extend a simulator with new endpoints (and possibly new middlewares) without requiring an upstream change to this repository.

Approach

This takes the simplest approach that could possibly work. It adds an "extension" property to the ServerOptions interface. It's just a function that, if present, will be invoked with the express router so that it can do whatever it wants to it.

netlify[bot] commented 1 year ago

Deploy Preview for simulacrum canceled.

Name Link
Latest commit b065a10ad6f5cb53a70453f1e8d3f0065b5e2210
Latest deploy log https://app.netlify.com/sites/simulacrum/deploys/645510e844ed7f0008eea11a