Skip to content

Commit

Permalink
添加网关项目模板 ZhonTai.Template.Gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
zhontai committed Jan 6, 2025
1 parent fe89cd5 commit e42d843
Show file tree
Hide file tree
Showing 20 changed files with 1,300 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/gateways/ZhonTai.Gateway.Yarp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NLog.Web;
using System.Reflection;
using ZhonTai.Gateway.Yarp.Core.Configs;

var builder = WebApplication.CreateBuilder(args);
Expand All @@ -8,8 +9,10 @@
//使用NLog日志
builder.Host.UseNLog();

//添加健康检查
builder.Services.AddHealthChecks();

//添加跨域
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAnyPolicy", policy =>
Expand All @@ -21,6 +24,7 @@
});
});

//添加代理
builder.Services.AddReverseProxy()
.LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"));

Expand All @@ -30,14 +34,16 @@

// Configure the HTTP request pipeline.

//使用跨域
app.UseCors("AllowAnyPolicy");

//使用健康检查
app.MapHealthChecks("/health");

//使用代理
app.MapReverseProxy();

//app.MapGet("/", () => $"The {Assembly.GetEntryAssembly()?.GetName().Name} has started.");

//首页
app.MapGet("/", async (HttpResponse response) =>
{
var gatewayConfig = builder.Configuration.GetSection("GatewayConfig").Get<GatewayConfig>();
Expand All @@ -54,7 +60,7 @@
}
else
{
html += "MyGateway.Host start!";
html += $"The {Assembly.GetEntryAssembly()?.GetName().Name} has started.";
}
html += "</body></html>";

Expand All @@ -63,5 +69,4 @@
await response.WriteAsync(html);
});


app.Run();
25 changes: 25 additions & 0 deletions templates/gateway/content/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
Loading

0 comments on commit e42d843

Please sign in to comment.