From eca9ca3a44b83d45797897492d455cf6c5e8049c Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 8 Mar 2024 14:48:41 +0800 Subject: [PATCH] feat ocelot --- Dlhis.Jinko.Face.sln | 6 ++++++ Src/Gateway/Dockerfile | 21 +++++++++++++++++++++ Src/Gateway/Gateway.csproj | 15 +++++++++++++++ Src/Gateway/Program.cs | 16 ++++++++++++++++ Src/Gateway/Properties/launchSettings.json | 14 ++++++++++++++ Src/Gateway/appsettings.Development.json | 8 ++++++++ Src/Gateway/appsettings.json | 9 +++++++++ Src/Gateway/ocelot.json | 20 ++++++++++++++++++++ 8 files changed, 109 insertions(+) create mode 100644 Src/Gateway/Dockerfile create mode 100644 Src/Gateway/Gateway.csproj create mode 100644 Src/Gateway/Program.cs create mode 100644 Src/Gateway/Properties/launchSettings.json create mode 100644 Src/Gateway/appsettings.Development.json create mode 100644 Src/Gateway/appsettings.json create mode 100644 Src/Gateway/ocelot.json diff --git a/Dlhis.Jinko.Face.sln b/Dlhis.Jinko.Face.sln index 0f893f5a..cf2e3f24 100644 --- a/Dlhis.Jinko.Face.sln +++ b/Dlhis.Jinko.Face.sln @@ -31,6 +31,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dlhis.Sys.Api", "Src\Dlhis. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dlhis.Basic.Api", "Src\Dlhis.Basic.Api\Dlhis.Basic.Api.csproj", "{1F337648-8A22-4601-A842-0F634FBA2825}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gateway", "Src\Gateway\Gateway.csproj", "{00DE1D49-8F1F-4EAA-B06F-CDE0EFAA03D3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -77,6 +79,10 @@ Global {1F337648-8A22-4601-A842-0F634FBA2825}.Debug|Any CPU.Build.0 = Debug|Any CPU {1F337648-8A22-4601-A842-0F634FBA2825}.Release|Any CPU.ActiveCfg = Release|Any CPU {1F337648-8A22-4601-A842-0F634FBA2825}.Release|Any CPU.Build.0 = Release|Any CPU + {00DE1D49-8F1F-4EAA-B06F-CDE0EFAA03D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {00DE1D49-8F1F-4EAA-B06F-CDE0EFAA03D3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {00DE1D49-8F1F-4EAA-B06F-CDE0EFAA03D3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {00DE1D49-8F1F-4EAA-B06F-CDE0EFAA03D3}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Src/Gateway/Dockerfile b/Src/Gateway/Dockerfile new file mode 100644 index 00000000..03f81a4b --- /dev/null +++ b/Src/Gateway/Dockerfile @@ -0,0 +1,21 @@ +#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. + +FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base +WORKDIR /app +EXPOSE 80 + +FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build +WORKDIR /src +COPY ["Src/Gateway/Gateway.csproj", "Src/Gateway/"] +RUN dotnet restore "Src/Gateway/Gateway.csproj" +COPY . . +WORKDIR "/src/Src/Gateway" +RUN dotnet build "Gateway.csproj" -c Release -o /app/build + +FROM build AS publish +RUN dotnet publish "Gateway.csproj" -c Release -o /app/publish /p:UseAppHost=false + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "Gateway.dll"] \ No newline at end of file diff --git a/Src/Gateway/Gateway.csproj b/Src/Gateway/Gateway.csproj new file mode 100644 index 00000000..82f8dae2 --- /dev/null +++ b/Src/Gateway/Gateway.csproj @@ -0,0 +1,15 @@ + + + + net6.0 + enable + enable + Linux + ..\.. + + + + + + + diff --git a/Src/Gateway/Program.cs b/Src/Gateway/Program.cs new file mode 100644 index 00000000..b3ba8e28 --- /dev/null +++ b/Src/Gateway/Program.cs @@ -0,0 +1,16 @@ +using Ocelot.DependencyInjection; +using Ocelot.Middleware; + +var builder = WebApplication.CreateBuilder(args); +builder.Configuration.AddJsonFile("ocelot.json", true, true); +// Add services to the container. + +builder.Services.AddOcelot(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. + +app.UseOcelot().Wait(); + +app.Run(); diff --git a/Src/Gateway/Properties/launchSettings.json b/Src/Gateway/Properties/launchSettings.json new file mode 100644 index 00000000..4384f481 --- /dev/null +++ b/Src/Gateway/Properties/launchSettings.json @@ -0,0 +1,14 @@ +{ + "profiles": { + "Gateway": { + "commandName": "Project", + "launchBrowser": false, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "http://localhost:5001" + } + }, + "$schema": "https://json.schemastore.org/launchsettings.json" +} \ No newline at end of file diff --git a/Src/Gateway/appsettings.Development.json b/Src/Gateway/appsettings.Development.json new file mode 100644 index 00000000..0c208ae9 --- /dev/null +++ b/Src/Gateway/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Src/Gateway/appsettings.json b/Src/Gateway/appsettings.json new file mode 100644 index 00000000..10f68b8c --- /dev/null +++ b/Src/Gateway/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Src/Gateway/ocelot.json b/Src/Gateway/ocelot.json new file mode 100644 index 00000000..055d3b47 --- /dev/null +++ b/Src/Gateway/ocelot.json @@ -0,0 +1,20 @@ +{ + "Routes": [ + { + "ServiceName": "basic", + "UpstreamPathTemplate": "/api/basic/{url}", + "UpstreamHttpMethod": [ "Get", "Post" ], + "DownstreamPathTemplate": "/api/{url}", + "DownstreamScheme": "http", + "DownstreamHostAndPorts": [ + { + "Host": "localhost", + "Port": 5002 + } + ] + } + ], + "GlobalConfiguration": { + //"BaseUrl": "http://localhost:5000" + } +} \ No newline at end of file