From 7aef2d1603c19d8f6ef40402c599bb16db5ecf43 Mon Sep 17 00:00:00 2001 From: wangyu Date: Tue, 29 Aug 2023 14:49:21 +0800 Subject: [PATCH] init --- .gitignore | 4 +++ Program.cs | 16 ++++++++++++ .../PublishProfiles/FolderProfile.pubxml | 18 +++++++++++++ WebProxy.csproj | 24 ++++++++++++++++++ WebProxy.sln | 25 +++++++++++++++++++ appsettings.json | 22 ++++++++++++++++ 6 files changed, 109 insertions(+) create mode 100644 .gitignore create mode 100644 Program.cs create mode 100644 Properties/PublishProfiles/FolderProfile.pubxml create mode 100644 WebProxy.csproj create mode 100644 WebProxy.sln create mode 100644 appsettings.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b7f4e76 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.vs +bin +obj +*.user diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..de43cfd --- /dev/null +++ b/Program.cs @@ -0,0 +1,16 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; + +var builder = WebApplication.CreateBuilder(args); + +var reverseProxyConfig = builder.Configuration.GetSection("ReverseProxy"); + +builder.Services.AddReverseProxy().LoadFromConfig(reverseProxyConfig); + +var app = builder.Build(); + +app.UseRouting(); + +app.MapReverseProxy(); + +app.Run(); \ No newline at end of file diff --git a/Properties/PublishProfiles/FolderProfile.pubxml b/Properties/PublishProfiles/FolderProfile.pubxml new file mode 100644 index 0000000..90b170f --- /dev/null +++ b/Properties/PublishProfiles/FolderProfile.pubxml @@ -0,0 +1,18 @@ + + + + + Release + Any CPU + bin\Release\net7.0\publish\linux-x64\ + FileSystem + <_TargetId>Folder + net7.0 + linux-x64 + true + true + false + + \ No newline at end of file diff --git a/WebProxy.csproj b/WebProxy.csproj new file mode 100644 index 0000000..1f6db86 --- /dev/null +++ b/WebProxy.csproj @@ -0,0 +1,24 @@ + + + + Exe + net7.0 + enable + enable + + + + + + + + + Always + + + + + + + + diff --git a/WebProxy.sln b/WebProxy.sln new file mode 100644 index 0000000..c61b94d --- /dev/null +++ b/WebProxy.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.33530.505 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebProxy", "WebProxy.csproj", "{F86D9D9B-DC67-42B4-AAEA-14562C6501BA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F86D9D9B-DC67-42B4-AAEA-14562C6501BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F86D9D9B-DC67-42B4-AAEA-14562C6501BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F86D9D9B-DC67-42B4-AAEA-14562C6501BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F86D9D9B-DC67-42B4-AAEA-14562C6501BA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7EF45312-00A6-406A-B1C6-813B8CA8B93A} + EndGlobalSection +EndGlobal diff --git a/appsettings.json b/appsettings.json new file mode 100644 index 0000000..cdf4986 --- /dev/null +++ b/appsettings.json @@ -0,0 +1,22 @@ +{ + "ReverseProxy": { + "Routes": { + "route1": { + "ClusterId": "yarp", + "Match": { + "Path": "{**catch-all}" + } + } + }, + "Clusters": { + "yarp": { + "LoadBalancingPolicy": "RoundRobin", + "Destinations": { + "openai": { + "Address": "https://api.openai.com/" + } + } + } + } + } +} \ No newline at end of file