microsoft / dev-proxy

Dev Proxy is an API simulator that helps you effortlessly test your app beyond the happy path.
https://aka.ms/devproxy
MIT License
534 stars 62 forks source link

Pass through plugin #926

Closed waldekmastykarz closed 1 week ago

waldekmastykarz commented 3 weeks ago

Offer a plugin that allows to pass through requests to a backend API. This would be invaluable for debugging/examining API requests in cloud service integration scenarios, where a cloud service calls a remote API and you want to examine what's on the request and response.

The usage scenario would be as follows:

waldekmastykarz commented 2 weeks ago

Here's sample configuration that we could use:

{
  "$schema": "https://raw.githubusercontent.com/microsoft/dev-proxy/main/schemas/v0.22.0/rc.schema.json",
  "plugins": [
    {
      "name": "DevToolsPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
      "configSection": "devTools"
    },
    {
      "name": "RewritePlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/dev-proxy-plugins.dll",
      "configSection": "rewritePlugin"
    }
  ],
  "urlsToWatch": [
    "https://jsonplaceholder.typicode.com/*",
    "https://jsonplaceholder.typicode.local/*",
    "http://jsonplaceholder.typicode.com/*",
    "http://jsonplaceholder.typicode.local/*"
  ],
  "rewritePlugin": {
    "rewritesFile": "devproxy-rewrites.json"
  },
  "devTools": {
    "preferredBrowser": "Edge"
  },
  "rate": 50,
  "logLevel": "information",
  "newVersionNotification": "stable",
  "showSkipMessages": true
}
{
  "rewrites": [
    {
      "in": {
        "host": "jsonplaceholder.typicode.local",
        "protocol": "http"
      },
      "out": {
        "host": "jsonplaceholder.typicode.com",
        "protocol": "https"
      }
    }
  ]
}

Rewriting the host is optional, but we'd use it to match rewrites to requests, so if you don't want to change the host, you could use the same host name in the in and out definition.

saasaTom commented 2 weeks ago

If you are using the MS Dev Tunnels tool, you can already inspect incoming requests at: https:/<tunnel_id>-<port>-inspect.usw2.devtunnels.ms/

The CLI output should write the actual URL where you can view the insecpt

waldekmastykarz commented 2 weeks ago

That's a good point! As a developer, you can choose if you want to just check the incoming request into the tunnel or the rewritten request going into the target cloud API.