-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from sentemon/gateway-microservice
- Loading branch information
Showing
32 changed files
with
658 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base | ||
WORKDIR /app | ||
EXPOSE 8000 | ||
|
||
RUN apt-get update && apt-get install -y curl && apt-get clean | ||
|
||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build | ||
|
||
WORKDIR /src | ||
|
||
COPY Gateway/Gateway/Gateway.csproj Gateway/Gateway/ | ||
|
||
RUN dotnet restore Gateway/Gateway/Gateway.csproj | ||
|
||
COPY . . | ||
|
||
WORKDIR /src/Gateway/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 | ||
|
||
FROM base AS final | ||
WORKDIR /app | ||
COPY --from=publish /app/publish . | ||
|
||
ENTRYPOINT ["dotnet", "Gateway.dll"] |
8 changes: 8 additions & 0 deletions
8
backend/src/Gateway/Gateway/Constants/AppSettingsConstants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Gateway.Constants; | ||
|
||
public class AppSettingsConstants | ||
{ | ||
public const string WebHostUrl = "WebHostUrl"; | ||
public const string AllowedOrigins = "AllowedOrigins"; | ||
public const string ReverseProxy = "ReverseProxy"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Gateway.Constants; | ||
|
||
public class CorsConstants | ||
{ | ||
public const string CorsPolicy = "CorsPolicy"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Yarp.ReverseProxy" Version="2.2.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Gateway.Constants; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
var allowedOrigins = builder.Configuration.GetSection(AppSettingsConstants.AllowedOrigins).Get<string[]>(); | ||
var hostingUrl = builder.Configuration[AppSettingsConstants.WebHostUrl]; | ||
var reverseProxyConfig = builder.Configuration.GetSection(AppSettingsConstants.ReverseProxy); | ||
|
||
builder.WebHost.UseUrls(hostingUrl ?? throw new ArgumentNullException(nameof(hostingUrl), "Hosting URL is not configured.")); | ||
|
||
builder.Services | ||
.AddCors(options => | ||
{ | ||
options.AddPolicy(CorsConstants.CorsPolicy, policyBuilder => | ||
{ | ||
policyBuilder | ||
.WithOrigins(allowedOrigins ?? throw new ArgumentNullException(nameof(allowedOrigins), | ||
"Allowed Origin URLs are not configured.")) | ||
.AllowCredentials() | ||
.AllowAnyHeader() | ||
.AllowAnyMethod(); | ||
}); | ||
}); | ||
|
||
builder.Services | ||
.AddReverseProxy() | ||
.LoadFromConfig(reverseProxyConfig); | ||
|
||
var app = builder.Build(); | ||
|
||
if (!app.Environment.IsDevelopment()) | ||
{ | ||
app.UseHttpsRedirection(); | ||
} | ||
|
||
app.UseCors(CorsConstants.CorsPolicy); | ||
|
||
app.MapReverseProxy(); | ||
|
||
app.MapGet("/health" ,() => Results.Ok("Healthy")); | ||
|
||
app.Run(); |
41 changes: 41 additions & 0 deletions
41
backend/src/Gateway/Gateway/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:37518", | ||
"sslPort": 44340 | ||
} | ||
}, | ||
"profiles": { | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "", | ||
"applicationUrl": "http://localhost:8000", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "", | ||
"applicationUrl": "https://localhost:7204;http://localhost:8000", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*", | ||
"WebHostUrl": "http://0.0.0.0:8000", | ||
"AllowedOrigins": [ "http://localhost:4200", "http://localhost:8080" ], | ||
"ReverseProxy": { | ||
"Routes": { | ||
"AuthService": { | ||
"ClusterId": "auth-service", | ||
"Match": { | ||
"Path": "/auth/{endpoint:regex(^graphql$|^health$)}" | ||
}, | ||
"Transforms": [ | ||
{ | ||
"PathRemovePrefix": "/auth" | ||
} | ||
] | ||
}, | ||
"PostService": { | ||
"ClusterId": "post-service", | ||
"Match": { | ||
"Path": "/post/{endpoint:regex(^graphql$|^health$)}" | ||
}, | ||
"Transforms": [ | ||
{ | ||
"PathRemovePrefix": "/post" | ||
} | ||
], | ||
"WebSocket": true | ||
} | ||
}, | ||
"Clusters": { | ||
"auth-service": { | ||
"Destinations": { | ||
"destination1": { | ||
"Address": "http://localhost:8001" | ||
} | ||
} | ||
}, | ||
"post-service": { | ||
"Destinations": { | ||
"destination1": { | ||
"Address": "http://localhost:8002" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.