Skip to content
  • Promote Your Product

Create Gateway Project ​

Project Introduction ​

API Gateway: Yarp Gateway

  • Reverse Proxy: Receives client requests and forwards them to appropriate backend services.
  • Load Balancing: Supports load balancing to distribute requests across multiple backend services, improving scalability and reliability.
  • Dynamic Configuration: Supports online dynamic addition and modification of clusters, route bindings, and domain HTTPS certificate bindings. Changes take effect immediately without restarting the service.

For more features, refer to the Yarp Official Documentation

Install or Upgrade Template ​

cs
dotnet new install ZhonTai.Template.Gateway

The upgrade template command is the same as the install template command.

Install Specific Version ​

cs
dotnet new install ZhonTai.Template.Gateway::10.1.0

View Help ​

cs
dotnet new MyGateway -h
-p, --port <port>   Port settings
                    Type: int
                    Default: 16010

Uninstall Template ​

cs
dotnet new uninstall ZhonTai.Template.Gateway

Create Gateway Project ​

cs
dotnet new MyGateway -n MyCompanyName.MyGateway

Customize Gateway Port ​

cs
dotnet new MyGateway -n MyCompanyName.MyGateway -p 16010

appsettings.json ​

Application configuration file, including route configuration, cluster configuration, certificate configuration, etc.

appsettings.json
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "Urls": "http://*:16010",
  "ReverseProxy": {
    "Routes": {
      // Permission management
      "admin": {
        "ClusterId": "admin",
        "Match": {
          "Path": "/api/admin/{**catch-all}",
          //"Methods": [ "POST", "GET", "DELETE", "PUT" ],
          "Hosts": []
        }
      },
      "admin-doc": {
        "ClusterId": "admin",
        "Match": {
          "Path": "/doc/admin/{**catch-all}",
          //"Methods": [ "POST", "GET", "DELETE", "PUT" ],
          "Hosts": []
        }
      },
      "admin-file": {
        "ClusterId": "admin",
        "Match": {
          "Path": "/upload/{**catch-all}",
          "Hosts": []
        }
      },
      // Development management
      "dev": {
        "ClusterId": "dev",
        "Match": {
          "Path": "/api/dev/{**catch-all}",
          //"Methods": [ "POST", "GET", "DELETE", "PUT" ],
          "Hosts": []
        }
      },
      "dev-doc": {
        "ClusterId": "dev",
        "Match": {
          "Path": "/doc/dev/{**catch-all}",
          //"Methods": [ "POST", "GET", "DELETE", "PUT" ],
          "Hosts": []
        }
      },
      // System management (includes permission management)
      "sys": {
        "ClusterId": "admin",
        "Match": {
          "Path": "/api/sys/{**catch-all}",
          "Hosts": []
        }
      },
      "sys-doc": {
        "ClusterId": "admin",
        "Match": {
          "Path": "/doc/sys/{**catch-all}",
          "Hosts": []
        }
      },
      // Business management
      "biz": {
        "ClusterId": "biz",
        "Match": {
          "Path": "/api/biz/{**catch-all}",
          //"Methods": [ "POST", "GET", "DELETE", "PUT" ],
          "Hosts": []
        }
      },
      "biz-doc": {
        "ClusterId": "biz",
        "Match": {
          "Path": "/doc/biz/{**catch-all}",
          //"Methods": [ "POST", "GET", "DELETE", "PUT" ],
          "Hosts": []
        }
      },
      // Member management
      "mem": {
        "ClusterId": "mem",
        "Match": {
          "Path": "/api/mem/{**catch-all}",
          //"Methods": [ "POST", "GET", "DELETE", "PUT" ],
          "Hosts": []
        }
      },
      "mem-doc": {
        "ClusterId": "mem",
        "Match": {
          "Path": "/doc/mem/{**catch-all}",
          //"Methods": [ "POST", "GET", "DELETE", "PUT" ],
          "Hosts": []
        }
      }
    },
    "Clusters": {
      "admin": {
        "Destinations": {
          "destination1": {
            "Address": "http://localhost:18010"
          }
        },
        "LoadBalancingPolicy": "RoundRobin"
      },
      "dev": {
        "Destinations": {
          "destination1": {
            "Address": "http://localhost:18020"
          }
        },
        "LoadBalancingPolicy": "RoundRobin"
      },
      "biz": {
        "Destinations": {
          "destination1": {
            "Address": "http://localhost:19010"
          }
        },
        "LoadBalancingPolicy": "RoundRobin"
      },
      "mem": {
        "Destinations": {
          "destination1": {
            "Address": "http://localhost:20010"
          }
        },
        "LoadBalancingPolicy": "RoundRobin"
      }
    }
  },
  // Gateway configuration
  "GatewayConfig": {
    // Module list
    "ModuleList": [
      {
        // Document name
        "Name": "Admin API Docs",
        // Document URL
        "Url": "/doc/admin/index.html"
      },
      {
        "Name": "System API Docs",
        "Url": "/doc/sys/index.html"
      },
       {
        "Name": "Development API Docs",
        "Url": "/doc/dev/index.html"
      },
      {
        "Name": "Business API Docs",
        "Url": "/doc/biz/index.html"
      },
      {
        "Name": "Member API Docs",
        "Url": "/doc/mem/index.html"
      }
    ],
    // Health check
    "HealthChecks": {
      // Enable
      "Enable": true,
      // Access path
      "Path": "/health"
    }
  }
}

launchSettings.json ​

Development startup configuration file, used to configure startup parameters such as environment variables, startup ports, etc.

launchSettings.json
{
  "profiles": {
    "MyGateway.Host": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "dotnetRunMessages": true,
      "applicationUrl": "http://localhost:16010"
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  },
  "$schema": "https://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:16010",
      "sslPort": 0
    }
  }
}