graph TD
A[YARP] -->|Static File| B[wwwroot]
A --> |/api-dst1| C[EndPoint1]
A --> |/api-dst2| D[EndPoint2]
style A fill:white,stroke-width:1px
style B fill:white,stroke-width:1px
要实现的目的:优先返回本地文件,然后转发到YARP配置的EndPoint。
假设使用.NET 6 创建项目、添加YARP依赖
1 2 3
dotnet new web -n MyYarp cd MyYarp dotnet add package Yarp.ReverseProxy
<!DOCTYPE html> <htmllang="en"> <head> <metacharset="UTF-8"> <metahttp-equiv="X-UA-Compatible"content="IE=edge"> <metaname="viewport"content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> This is the index page </body> </html>