Skip to content

Commit cfbe598

Browse files
style: add language to code snippets (#36701)
1 parent 97c0eca commit cfbe598

12 files changed

Lines changed: 72 additions & 42 deletions

aspnetcore/fundamentals/servers/yarp/ab-testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ A/B testing and rolling upgrades require procedures for dynamically assigning in
1818

1919
## Example
2020

21-
```
21+
```csharp
2222
app.MapReverseProxy(proxyPipeline =>
2323
{
2424
// Custom cluster selection

aspnetcore/fundamentals/servers/yarp/authn-authz.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ Example:
5151
[Authorization policies](/aspnet/core/security/authorization/policies) are an ASP.NET Core concept that the proxy utilizes. The proxy provides the above configuration to specify a policy per route and the rest is handled by existing ASP.NET Core authentication and authorization components.
5252

5353
Authorization policies can be configured in the application as follows:
54-
```
54+
55+
```csharp
5556
services.AddAuthorization(options =>
5657
{
5758
options.AddPolicy("customPolicy", policy =>
@@ -61,7 +62,7 @@ services.AddAuthorization(options =>
6162

6263
In Program.cs add the Authorization and Authentication middleware.
6364

64-
```
65+
```csharp
6566
app.UseAuthentication();
6667
app.UseAuthorization();
6768

aspnetcore/fundamentals/servers/yarp/config-providers.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ For additional fields see [ClusterConfig](xref:Yarp.ReverseProxy.Configuration.C
4242

4343
The `InMemoryConfigProvider` implements `IProxyConfigProvider` and enables specifying routes and clusters directly in code by calling `LoadFromMemory`.
4444

45-
```
45+
```csharp
4646
services.AddReverseProxy().LoadFromMemory(routes, clusters);
4747
```
4848

4949
To update the config later, resolve the `InMemoryConfigProvider` from the services container and call `Update` with the new lists of routes and clusters.
5050

51-
```
51+
```csharp
5252
httpContext.RequestServices.GetRequiredService<InMemoryConfigProvider>().Update(routes, clusters);
5353
```
5454

@@ -87,13 +87,15 @@ Once the new configuration has been validated and applied, the proxy will regist
8787
## Multiple Configuration Sources
8888
As of 1.1, YARP supports loading the proxy configuration from multiple sources. Multiple `IProxyConfigProvider`'s can be registered as singleton services and all will be resolved and combined. The sources may be the same or different types such as IConfiguration or InMemory. Routes can reference clusters from other sources. Note merging partial config from different sources for a given route or cluster is not supported.
8989

90-
```
90+
```csharp
9191
services.AddReverseProxy()
9292
.LoadFromConfig(Configuration.GetSection("ReverseProxy1"))
9393
.LoadFromConfig(Configuration.GetSection("ReverseProxy2"));
9494
```
95+
9596
or
96-
```
97+
98+
```csharp
9799
services.AddReverseProxy()
98100
.LoadFromMemory(routes, clusters)
99101
.LoadFromConfig(Configuration.GetSection("ReverseProxy"));

aspnetcore/fundamentals/servers/yarp/cors.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Example:
5151
[CORS policies](/aspnet/core/security/cors#cors-with-named-policy-and-middleware) are an ASP.NET Core concept that the proxy utilizes. The proxy provides the above configuration to specify a policy per route and the rest is handled by existing ASP.NET Core CORS Middleware.
5252

5353
CORS policies can be configured in the application as follows:
54-
```
54+
```csharp
5555
services.AddCors(options =>
5656
{
5757
options.AddPolicy("customPolicy", builder =>
@@ -63,7 +63,7 @@ services.AddCors(options =>
6363

6464
Then add the CORS middleware.
6565

66-
```
66+
```csharp
6767
app.UseCors();
6868

6969
app.MapReverseProxy();

aspnetcore/fundamentals/servers/yarp/dests-health-checks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ Global parameters are set via the options mechanism using `TransportFailureRateH
280280
* `DefaultFailureRateLimit` - default failure rate limit for a destination to be marked as unhealthy that is applied if it's not set on a cluster's metadata. The value is in range `(0,1)`. Default is `0.3` (30%).
281281

282282
Global policy options can be set in code as follows:
283+
283284
```csharp
284285
services.Configure<TransportFailureRateHealthPolicyOptions>(o =>
285286
{

aspnetcore/fundamentals/servers/yarp/kubernetes-ingress.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Before we continue with this tutorial, make sure you have the following ready...
4141
4242
In the meantime, the YARP ingress controller must be built locally and deploy it. In the root of the repository, run:
4343

44-
```
44+
```bash
4545
docker build . -t {REGISTRY_NAME}/yarp-controller:{TAG} -f .\src\Kubernetes.Controller\Dockerfile
4646
docker push {REGISTRY_NAME}/yarp-controller:{TAG}
4747
```
@@ -51,27 +51,27 @@ In the preceding commands, the `{REGISTRY_NAME}` placeholder is the name of the
5151
The first step is to deploy the YARP ingress controller to the Kubernetes cluster. This can be done by navigating to [Kubernetes Ingress sample](https://github.com/dotnet/yarp/tree/release/latest/samples/KubernetesIngress.Sample) `\samples\KubernetesIngress.Sample\Ingress`
5252
and running (after modifying `ingress-controller.yaml` with the same `REGISTRY_NAME` and `TAG`):
5353

54-
```
54+
```bash
5555
kubectl apply -f ingress-controller.yaml
5656
```
5757

5858
To verify that the ingress controller has been deployed, run:
5959

60-
```
60+
```bash
6161
kubectl get pods -n yarp
6262
```
6363

6464
You can then check logs from the ingress controller by running:
6565

66-
```
66+
```bash
6767
kubectl logs {POD NAME} -n yarp
6868
```
6969

7070
All services, deployments, and pods for YARP are in the namespace `yarp`. Make sure to include `-n yarp` if you want to check on the status of yarp.
7171

7272
Next, build and deploy the ingress. In the root of the repository, run:
7373

74-
```
74+
```bash
7575
docker build . -t {REGISTRY_NAME}/yarp:<TAG> -f .\samples\KuberenetesIngress.Sample\Ingress\Dockerfile
7676
docker push {REGISTRY_NAME}/yarp:{TAG}
7777
```
@@ -80,7 +80,7 @@ In the preceding commands, the `{REGISTRY_NAME}` placeholder is the name of the
8080

8181
Finally, we need to deploy the ingress itself to Kubernetes. Navigate to the `Ingress` directory and modify the `ingress.yaml` file for your registry and tag specified earlier and run:
8282

83-
```
83+
```bash
8484
kubectl apply -f .\ingress.yaml
8585
```
8686

@@ -90,28 +90,28 @@ At this point, your ingress and controller should be running.
9090

9191
To use the ingress, we now need to deploy an application to Kubernetes. Navigate to `samples\KuberenetesIngress.Sample\backend` and run:
9292

93-
```
93+
```bash
9494
docker build . -t {REGISTRY_NAME}/backend:{TAG}
9595
docker push {REGISTRY_NAME}/backend:{TAG}
9696
```
9797

9898
And deploying it to Kubernetes by running, after modifying `backend.yaml` with the same registry name (`{REGISTRY_NAME}`) and tag (`{TAG}`):
9999

100-
```
100+
```bash
101101
kubectl apply -f .\backend.yaml
102102
```
103103

104104
## Creating the ingress definition
105105

106106
Finally, once we have deployed the backend application, we need to route traffic to the backend. To do this, run in the `backend` directory:
107107

108-
```
108+
```bash
109109
kubectl apply -f .\ingress-sample.yaml
110110
```
111111

112112
And then execute the following command to get the external IP of the ingress, the name of the related service being `yarp-proxy`:
113113

114-
```
114+
```bash
115115
kubectl get service -n yarp
116116
```
117117

aspnetcore/fundamentals/servers/yarp/lets-encrypt.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ YARP can support the certificate authority [Lets Encrypt](https://letsencrypt.or
2323

2424
Add the `LettuceEncrypt` package dependency:
2525

26-
```csproj
26+
```xml
2727
<PackageReference Include="LettuceEncrypt" Version="1.1.2" />
2828
```
2929

aspnetcore/fundamentals/servers/yarp/middleware.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Middleware added to your application pipeline will see the request in different
3636

3737
[ReverseProxyIEndpointRouteBuilderExtensions](xref:Microsoft.AspNetCore.Builder.ReverseProxyIEndpointRouteBuilderExtensions) provides an overload of `MapReverseProxy` that lets you build a middleware pipeline that will run only for requests matched to proxy configured routes.
3838

39-
```
39+
```csharp
4040
app.MapReverseProxy(proxyPipeline =>
4141
{
4242
proxyPipeline.Use((context, next) =>

aspnetcore/fundamentals/servers/yarp/rate-limiting.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ The reverse proxy can be used to rate-limit requests before they are proxied to
2222
No rate limiting is performed on requests unless enabled in the route or application configuration. However, the Rate Limiting middleware (`app.UseRateLimiter()`) can apply a default limiter applied to all routes, and this doesn't require any opt-in from the config.
2323

2424
Example:
25+
2526
```csharp
2627
services.AddRateLimiter(options => options.GlobalLimiter = globalLimiter);
2728
```
@@ -58,6 +59,7 @@ Example:
5859
[RateLimiter policies](/aspnet/core/performance/rate-limit) are an ASP.NET Core concept that the proxy utilizes. The proxy provides the above configuration to specify a policy per route and the rest is handled by existing ASP.NET Core rate limiting middleware.
5960

6061
RateLimiter policies can be configured in services as follows:
62+
6163
```csharp
6264
services.AddRateLimiter(options =>
6365
{

aspnetcore/fundamentals/servers/yarp/session-affinity.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Session affinity is a mechanism to bind (affinitize) a causally related request
2020
Session affinity services are registered in the DI container automatically by `AddReverseProxy()`. The middleware `UseSessionAffinity()` is included by default in the parameterless MapReverseProxy method. If you are customizing the proxy pipeline, place the first middleware **before** adding `UseLoadBalancing()`.
2121

2222
Example:
23+
2324
```csharp
2425
app.MapReverseProxy(proxyPipeline =>
2526
{

0 commit comments

Comments
 (0)