通过


devproxyrc

默认开发代理配置文件。

开发代理支持配置文件的 JSON () 和 YAML (, ) 格式。 默认文件是 ,但开发代理也自动发现 和 。

注释

架构验证()仅适用于基于 JSON 的配置文件。 YAML 配置文件在运行时不会针对架构进行验证。

文件: devproxyrc.json

{
  "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.2.0/rc.schema.json",
  "plugins": [
    {
      "name": "RetryAfterPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll"
    },
    {
      "name": "GenericRandomErrorPlugin",
      "enabled": true,
      "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll",
      "configSection": "genericRandomErrorPlugin"
    }
  ],
  "urlsToWatch": [
    "https://jsonplaceholder.typicode.com/*"
  ],
  "genericRandomErrorPlugin": {
    "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v2.2.0/genericrandomerrorplugin.schema.json",
    "errorsFile": "devproxy-errors.json",
    "rate": 50
  },
  "logLevel": "information",
  "newVersionNotification": "stable",
  "showSkipMessages": true,
  "showTimestamps": true,
  "validateSchemas": true
}

文件: devproxyrc.yaml(等效 YAML 配置)

plugins:
  - name: RetryAfterPlugin
    enabled: true
    pluginPath: "~appFolder/plugins/DevProxy.Plugins.dll"
  - name: GenericRandomErrorPlugin
    enabled: true
    pluginPath: "~appFolder/plugins/DevProxy.Plugins.dll"
    configSection: genericRandomErrorPlugin

urlsToWatch:
  - "https://jsonplaceholder.typicode.com/*"

genericRandomErrorPlugin:
  errorsFile: devproxy-errors.json
  rate: 50

logLevel: information
newVersionNotification: stable
showSkipMessages: true
showTimestamps: true
validateSchemas: true

YAML 配置支持可重用配置块的定位点和合并键:

# Define reusable response templates using YAML anchors
throttled: &throttled
  statusCode: 429
  body: '{"error": "Too many requests"}'

mocks:
  - request:
      url: https://api.example.com/users
    response:
      <<: *throttled
  - request:
      url: https://api.example.com/groups
    response:
      <<: *throttled