Skip to content

Commit 900ccb1

Browse files
committed
add yarp on the top of apps #4
1 parent 8cb34cb commit 900ccb1

File tree

10 files changed

+270
-27
lines changed

10 files changed

+270
-27
lines changed

README.md

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,48 @@ $ npm run dev
3333

3434
- Public Apis:
3535

36-
> Frontend: [http://localhost:3000/products](http://localhost:3000/products)
37-
>
38-
> Backend: [http://localhost:5002](http://localhost:5002)
39-
>
4036
> Tye Dashboard: [http://localhost:8000](http://localhost:8000)
4137
38+
<table>
39+
<thead>
40+
<th>No.</th>
41+
<th>Service name</th>
42+
<th>Service uri</th>
43+
</thead>
44+
<tbody>
45+
<tr>
46+
<td>1</td>
47+
<td>gateway</td>
48+
<td><a href="http://localhost:5000">http://localhost:5000</a></td>
49+
</tr>
50+
<tr>
51+
<td>2</td>
52+
<td>product (internal)</td>
53+
<td><a href="http://localhost:5002">http://localhost:5002</a></td>
54+
</tr>
55+
<tr>
56+
<td>3</td>
57+
<td>customer (internal)</td>
58+
<td><a href="http://localhost:5003">http://localhost:5003</a></td>
59+
</tr>
60+
<tr>
61+
<td>4</td>
62+
<td>setting (internal)</td>
63+
<td><a href="http://localhost:5005">http://localhost:5005</a></td>
64+
</tr>
65+
<tr>
66+
<td>5</td>
67+
<td>audit (internal)</td>
68+
<td><a href="http://localhost:5010">http://localhost:5010</a></td>
69+
</tr>
70+
<tr>
71+
<td>6</td>
72+
<td>frontend</td>
73+
<td><a href="http://localhost:3000">http://localhost:3000</a></td>
74+
</tr>
75+
</tbody>
76+
</table>
77+
4278
# Business Usecases
4379

4480
![](assets/usecase_diagram.png)

coolstore.sln

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,24 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoolStore.AppContracts", "s
3838
EndProject
3939
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Setting", "Setting", "{EEA08CE8-4834-4D36-ADE0-24F5F471AF6A}"
4040
EndProject
41-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SettingService.Core", "src\Setting\SettingService.Core\SettingService.Core.csproj", "{340E9BEE-1CE0-43EE-A33B-0C039D7FCE5B}"
41+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SettingService.Core", "src\Setting\SettingService.Core\SettingService.Core.csproj", "{340E9BEE-1CE0-43EE-A33B-0C039D7FCE5B}"
4242
EndProject
4343
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SettingService.Infrastructure", "src\Setting\SettingService.Infrastructure\SettingService.Infrastructure.csproj", "{2561F40E-103B-4E80-B057-91D7AD44E3D9}"
4444
EndProject
4545
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SettingService.Application", "src\Setting\SettingService.Application\SettingService.Application.csproj", "{A9F94E23-850D-4750-94C1-9C26B25A3DED}"
4646
EndProject
4747
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Customer", "Customer", "{5D18FF27-2948-433A-A40F-77C778A705C1}"
4848
EndProject
49-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomerService.Core", "src\Customer\CustomerService.Core\CustomerService.Core.csproj", "{C2531C6A-185A-4120-B098-946855684626}"
49+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomerService.Core", "src\Customer\CustomerService.Core\CustomerService.Core.csproj", "{C2531C6A-185A-4120-B098-946855684626}"
5050
EndProject
5151
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomerService.Infrastructure", "src\Customer\CustomerService.Infrastructure\CustomerService.Infrastructure.csproj", "{A26F7B4F-F725-4018-954A-C3D7925C2A30}"
5252
EndProject
5353
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomerService.Application", "src\Customer\CustomerService.Application\CustomerService.Application.csproj", "{4F623591-01CB-4CCE-9BDD-9B0CBC6D8F8E}"
5454
EndProject
55+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Gateways", "Gateways", "{4DE0371F-85C0-4CC2-8457-08EB3F3F0A4D}"
56+
EndProject
57+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AppGateway", "src\Gateways\AppGateway\AppGateway.csproj", "{8CFC9025-2F85-4196-9AE7-74FE68AB79A4}"
58+
EndProject
5559
Global
5660
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5761
Debug|Any CPU = Debug|Any CPU
@@ -114,6 +118,10 @@ Global
114118
{4F623591-01CB-4CCE-9BDD-9B0CBC6D8F8E}.Debug|Any CPU.Build.0 = Debug|Any CPU
115119
{4F623591-01CB-4CCE-9BDD-9B0CBC6D8F8E}.Release|Any CPU.ActiveCfg = Release|Any CPU
116120
{4F623591-01CB-4CCE-9BDD-9B0CBC6D8F8E}.Release|Any CPU.Build.0 = Release|Any CPU
121+
{8CFC9025-2F85-4196-9AE7-74FE68AB79A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
122+
{8CFC9025-2F85-4196-9AE7-74FE68AB79A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
123+
{8CFC9025-2F85-4196-9AE7-74FE68AB79A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
124+
{8CFC9025-2F85-4196-9AE7-74FE68AB79A4}.Release|Any CPU.Build.0 = Release|Any CPU
117125
EndGlobalSection
118126
GlobalSection(SolutionProperties) = preSolution
119127
HideSolutionNode = FALSE
@@ -133,6 +141,7 @@ Global
133141
{C2531C6A-185A-4120-B098-946855684626} = {5D18FF27-2948-433A-A40F-77C778A705C1}
134142
{A26F7B4F-F725-4018-954A-C3D7925C2A30} = {5D18FF27-2948-433A-A40F-77C778A705C1}
135143
{4F623591-01CB-4CCE-9BDD-9B0CBC6D8F8E} = {5D18FF27-2948-433A-A40F-77C778A705C1}
144+
{8CFC9025-2F85-4196-9AE7-74FE68AB79A4} = {4DE0371F-85C0-4CC2-8457-08EB3F3F0A4D}
136145
EndGlobalSection
137146
GlobalSection(ExtensibilityGlobals) = postSolution
138147
SolutionGuid = {7B983152-0931-4714-9EDE-BD7DE35C758E}

restclient.http

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,22 @@
1-
@host = http://localhost:5002
2-
@setting-host = http://localhost:5005
3-
@customer-host = http://localhost:5003
1+
@host = http://localhost:5000
42

53
###
6-
POST {{host}}/api/products-query HTTP/1.1
4+
GET {{host}}/product-api/api/products?api-version=1.0 HTTP/1.1
75
content-type: {{contentType}}
8-
9-
{
10-
"filters": [
11-
{
12-
"fieldName": "Name",
13-
"comparision": "Contains",
14-
"fieldValue": "test product"
15-
}
16-
],
17-
"sorts": ["nameDesc"],
18-
"page": 1,
19-
"pageSize": 20
20-
}
6+
x-query: {"filters":[{"fieldName": "Name", "comparision": "Contains", "fieldValue": "test"}],"sorts":["nameDesc"],"page":1,"pageSize":20}
217

228
###
239
@id = 23537dac-303f-446f-be2a-1dbea22b3eba
24-
GET {{host}}/api/products/{{id}} HTTP/1.1
10+
GET {{host}}/product-api/api/products/{{id}}?api-version=1.0 HTTP/1.1
2511
content-type: {{contentType}}
2612

2713
###
2814
@country-id = 18a4a8ae-3338-484a-a4ed-6e64d13d84dc
29-
GET {{setting-host}}/api/countries/{{country-id}} HTTP/1.1
15+
GET {{host}}/setting-api/api/countries/{{country-id}} HTTP/1.1
3016
content-type: {{contentType}}
3117

3218
###
33-
POST {{host}}/api/products HTTP/1.1
19+
POST {{host}}/product-api/api/products?api-version=1.0 HTTP/1.1
3420
content-type: {{contentType}}
3521

3622
{
@@ -43,7 +29,7 @@ content-type: {{contentType}}
4329
}
4430

4531
###
46-
POST {{customer-host}}/api/customers HTTP/1.1
32+
POST {{host}}/customer-api/api/customers?api-version=1.0 HTTP/1.1
4733
content-type: {{contentType}}
4834

4935
{
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.ReverseProxy" Version="1.0.0-preview.9.*" />
9+
</ItemGroup>
10+
11+
</Project>

src/Gateways/AppGateway/Program.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Hosting;
3+
4+
namespace AppGateway
5+
{
6+
public class Program
7+
{
8+
public static void Main(string[] args)
9+
{
10+
CreateHostBuilder(args).Build().Run();
11+
}
12+
13+
public static IHostBuilder CreateHostBuilder(string[] args) =>
14+
Host.CreateDefaultBuilder(args)
15+
.ConfigureWebHostDefaults(webBuilder =>
16+
{
17+
webBuilder.UseStartup<Startup>();
18+
});
19+
}
20+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"profiles": {
3+
"AppGateway": {
4+
"commandName": "Project",
5+
"dotnetRunMessages": "true",
6+
"launchBrowser": true,
7+
"applicationUrl": "http://localhost:5000",
8+
"environmentVariables": {
9+
"ASPNETCORE_ENVIRONMENT": "Development"
10+
}
11+
}
12+
}
13+
}

src/Gateways/AppGateway/Startup.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Microsoft.Extensions.Hosting;
5+
using Microsoft.Extensions.Configuration;
6+
7+
namespace AppGateway
8+
{
9+
public class Startup
10+
{
11+
private readonly IConfiguration _configuration;
12+
13+
public Startup(IConfiguration configuration)
14+
{
15+
_configuration = configuration;
16+
}
17+
18+
public void ConfigureServices(IServiceCollection services)
19+
{
20+
services.AddReverseProxy()
21+
.LoadFromConfig(_configuration.GetSection("ReverseProxy"));
22+
}
23+
24+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
25+
{
26+
if (env.IsDevelopment())
27+
{
28+
app.UseDeveloperExceptionPage();
29+
}
30+
31+
app.UseRouting();
32+
33+
app.UseEndpoints(endpoints =>
34+
{
35+
endpoints.MapReverseProxy();
36+
});
37+
}
38+
}
39+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
},
9+
"ReverseProxy": {
10+
"Clusters": {
11+
"productappcluster": {
12+
"Destinations": {
13+
"productappcluster/destination1": {
14+
"Address": "http://localhost:5002/"
15+
}
16+
}
17+
},
18+
"customerappcluster": {
19+
"Destinations": {
20+
"customerappcluster/destination1": {
21+
"Address": "http://localhost:5003/"
22+
}
23+
}
24+
},
25+
"settingappcluster": {
26+
"Destinations": {
27+
"settingappcluster/destination1": {
28+
"Address": "http://localhost:5005/"
29+
}
30+
}
31+
}
32+
}
33+
}
34+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
},
9+
"AllowedHosts": "*",
10+
"ReverseProxy": {
11+
"Routes": [
12+
{
13+
"RouteId": "productapp",
14+
"ClusterId": "productappcluster",
15+
"Match": {
16+
"Path": "/product-api/{**catch-all}"
17+
},
18+
"Transforms": [
19+
{ "PathRemovePrefix": "/product-api" },
20+
{
21+
"X-Forwarded": "proto,host,for,pathbase",
22+
"Append": "true",
23+
"Prefix": "X-Forwarded-"
24+
},
25+
{ "RequestHeadersCopy": "true" },
26+
{ "RequestHeaderOriginalHost": "true" }
27+
]
28+
},
29+
{
30+
"RouteId": "customerapp",
31+
"ClusterId": "customerappcluster",
32+
"Match": {
33+
"Path": "/customer-api/{**catch-all}"
34+
},
35+
"Transforms": [
36+
{ "PathRemovePrefix": "/customer-api" },
37+
{
38+
"X-Forwarded": "proto,host,for,pathbase",
39+
"Append": "true",
40+
"Prefix": "X-Forwarded-"
41+
},
42+
{ "RequestHeadersCopy": "true" },
43+
{ "RequestHeaderOriginalHost": "true" }
44+
]
45+
},
46+
{
47+
"RouteId": "settingapp",
48+
"ClusterId": "settingappcluster",
49+
"Match": {
50+
"Path": "/setting-api/{**catch-all}"
51+
},
52+
"Transforms": [
53+
{ "PathRemovePrefix": "/setting-api" },
54+
{
55+
"X-Forwarded": "proto,host,for,pathbase",
56+
"Append": "true",
57+
"Prefix": "X-Forwarded-"
58+
},
59+
{ "RequestHeadersCopy": "true" },
60+
{ "RequestHeaderOriginalHost": "true" }
61+
]
62+
}
63+
],
64+
65+
"Clusters": {
66+
"productappcluster": {
67+
"Destinations": {
68+
"productappcluster/destination1": {
69+
"Address": "http://productserviceapp:5002/"
70+
}
71+
}
72+
},
73+
"customerappcluster": {
74+
"Destinations": {
75+
"customerappcluster/destination1": {
76+
"Address": "http://customerapp:5003/"
77+
}
78+
}
79+
},
80+
"settingappcluster": {
81+
"Destinations": {
82+
"settingappcluster/destination1": {
83+
"Address": "http://settingapp:5005/"
84+
}
85+
}
86+
}
87+
}
88+
89+
}
90+
}

tye.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ services:
2525
bindings:
2626
- port: 6379
2727

28+
- name: gatewayapp
29+
project: src/Gateways/AppGateway/AppGateway.csproj
30+
bindings:
31+
- port: 5000
32+
2833
- name: productserviceapp
2934
project: src/Product/ProductService.Application/ProductService.Application.csproj
3035
env:

0 commit comments

Comments
 (0)