Skip to content

Commit

Permalink
[APIGateway] Update Ocelot Routes and Code Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hidayatarg committed Oct 12, 2023
1 parent aca72d3 commit 6dbcbf2
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 128 deletions.
10 changes: 6 additions & 4 deletions src/ApiGateways/OcelotApiGw/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using Ocelot.Middleware;

var builder = WebApplication.CreateBuilder(args);
var env = builder.Environment;
var env = builder.Environment.EnvironmentName;

// configureAppConfiguration
builder.Configuration.AddJsonFile($"ocelot.{env}.json", true, true);
builder.Configuration.AddJsonFile($"ocelot.{env}.json", false, true);


// logging configuration
Expand All @@ -17,8 +17,10 @@

var app = builder.Build();

app.UseOcelot().Wait();
app.UseHttpsRedirection();
await app.UseOcelot();
app.UseAuthorization();

app.MapGet("/", () => "Hello World!");
app.MapControllers();

app.Run();
248 changes: 124 additions & 124 deletions src/ApiGateways/OcelotApiGw/ocelot.Local.json
Original file line number Diff line number Diff line change
@@ -1,126 +1,126 @@
{
"Routes": [
// Catalog API
{
"DownstreamPathTemplate": "/api/catalog",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 8000
}
],
"UpstreamPathTemplate": "/catalog",
"UpstreamHttpMethod": [ "GET", "POST", "PUT" ]
},
{
"DownstreamPathTemplate": "/api/catalog/{id}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 8000
}
],
"UpstreamPathTemplate": "/catalog/{id}",
"UpstreamHttpMethod": [ "GET", "DELETE" ]
},
{
"DownstreamPathTemplate": "/api/catalog/GetProductByCategory/{category}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 8000
}
],
"UpstreamPathTemplate": "/catalog/GetProductByCategory/{category}",
"UpstreamHttpMethod": [ "GET" ]
},
//Basket API
{
"DownstreamPathTemplate": "/api/v1/Basket/{userName}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": "8001"
}
],
"UpstreamPathTemplate": "/Basket/{userName}",
"UpstreamHttpMethod": [ "GET", "DELETE" ]
},
{
"DownstreamPathTemplate": "/api/v1/Basket",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": "8001"
}
],
"UpstreamPathTemplate": "/Basket",
"UpstreamHttpMethod": [ "POST" ]
},
{
"DownstreamPathTemplate": "/api/v1/Basket/Checkout",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": "8001"
}
],
"UpstreamPathTemplate": "/Basket/Checkout",
"UpstreamHttpMethod": [ "POST" ],
"RateLimitOptions": {
"ClientWhitelist": [],
"EnableRateLimiting": true,
"Period": "3s",
"PeriodTimespan": 1,
"Limit": 1
}
},
//Discount API
{
"DownstreamPathTemplate": "/api/v1/Discount/{productName}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": "8002"
}
],
"UpstreamPathTemplate": "/Discount/{productName}",
"UpstreamHttpMethod": [ "GET", "DELETE" ]
},
{
"DownstreamPathTemplate": "/api/v1/Discount",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": "8002"
}
],
"UpstreamPathTemplate": "/Discount",
"UpstreamHttpMethod": [ "PUT", "POST" ]
},
//Order API
{
"DownstreamPathTemplate": "/api/v1/Order/{userName}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": "8004"
}
],
"UpstreamPathTemplate": "/Order/{userName}",
"UpstreamHttpMethod": [ "GET" ]
}
],
"GlobalConfiguration": {
"BaseUrl": "http://localhost:5010"
}
"Routes": [
// Catalog API
{
"DownstreamPathTemplate": "/api/v1/catalog",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 8000
}
],
"UpstreamPathTemplate": "/catalog",
"UpstreamHttpMethod": ["GET", "POST", "PUT"]
},
{
"DownstreamPathTemplate": "/api/v1/catalog/{id}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 8000
}
],
"UpstreamPathTemplate": "/catalog/{id}",
"UpstreamHttpMethod": ["GET", "DELETE"]
},
{
"DownstreamPathTemplate": "/api/v1/catalog/GetProductByCategory/{category}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 8000
}
],
"UpstreamPathTemplate": "/catalog/GetProductByCategory/{category}",
"UpstreamHttpMethod": ["GET"]
},
//Basket API
{
"DownstreamPathTemplate": "/api/v1/Basket/{userName}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": "8001"
}
],
"UpstreamPathTemplate": "/Basket/{userName}",
"UpstreamHttpMethod": ["GET", "DELETE"]
},
{
"DownstreamPathTemplate": "/api/v1/Basket",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": "8001"
}
],
"UpstreamPathTemplate": "/Basket",
"UpstreamHttpMethod": ["POST"]
},
{
"DownstreamPathTemplate": "/api/v1/Basket/Checkout",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": "8001"
}
],
"UpstreamPathTemplate": "/Basket/Checkout",
"UpstreamHttpMethod": ["POST"],
"RateLimitOptions": {
"ClientWhitelist": [],
"EnableRateLimiting": true,
"Period": "3s",
"PeriodTimespan": 1,
"Limit": 1
}
},
//Discount API
{
"DownstreamPathTemplate": "/api/v1/Discount/{productName}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": "8002"
}
],
"UpstreamPathTemplate": "/Discount/{productName}",
"UpstreamHttpMethod": ["GET", "DELETE"]
},
{
"DownstreamPathTemplate": "/api/v1/Discount",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": "8002"
}
],
"UpstreamPathTemplate": "/Discount",
"UpstreamHttpMethod": ["PUT", "POST"]
},
//Order API
{
"DownstreamPathTemplate": "/api/v1/Order/{userName}",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": "8004"
}
],
"UpstreamPathTemplate": "/Order/{userName}",
"UpstreamHttpMethod": ["GET"]
}
],
"GlobalConfiguration": {
"BaseUrl": "http://localhost:5010"
}
}

0 comments on commit 6dbcbf2

Please sign in to comment.