Skip to content

Commit

Permalink
API URL sets in CLient side
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-atharva committed May 1, 2023
1 parent 115a0c5 commit f7b1d61
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/Presentation/Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
global using BlazorEcommerce.Client.Services.ProductService;
global using BlazorEcommerce.Client.Services.ProductTypeService;
global using BlazorEcommerce.Shared;
global using BlazorEcommerce.Shared.Response.Abstract;
global using BlazorEcommerce.Shared.Response.Concrete;
global using BlazorEcommerce.Shared.Cart;
global using BlazorEcommerce.Shared.Product;
global using BlazorEcommerce.Shared.Order;
global using BlazorEcommerce.Shared.Product;
global using BlazorEcommerce.Shared.Response.Concrete;
global using System.Net.Http.Json;
using BlazorEcommerce.Client;
using Blazored.LocalStorage;
Expand All @@ -25,7 +24,9 @@

builder.Services.AddBlazoredLocalStorage();
builder.Services.AddMudServices();
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
//builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
var apiUrl = builder.Configuration.GetValue<string>("AppConfig:ApiUrl");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(!string.IsNullOrEmpty(apiUrl) ? apiUrl : builder.HostEnvironment.BaseAddress) });
builder.Services.AddScoped<IProductService, ProductService>();
builder.Services.AddScoped<ICategoryService, CategoryService>();
builder.Services.AddScoped<ICartService, CartService>();
Expand Down
5 changes: 5 additions & 0 deletions src/Presentation/Client/wwwroot/appsettings.development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"AppConfig": {
"ApiUrl": "https://localhost:7018"
}
}
5 changes: 5 additions & 0 deletions src/Presentation/Client/wwwroot/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"AppConfig": {
"ApiUrl": "https://localhost:7018"
}
}
9 changes: 9 additions & 0 deletions src/Presentation/Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@

builder.Services.AddHttpContextAccessor();

builder.Services.AddCors(options =>
{
options.AddPolicy("all", builder => builder.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod());
});

var app = builder.Build();

// Initialise and seed the database
Expand Down Expand Up @@ -82,4 +89,6 @@
app.MapControllers();
app.MapFallbackToFile("index.html");

app.UseCors("all");

app.Run();
3 changes: 0 additions & 3 deletions src/Presentation/Server/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
"ConnectionStrings": {
"Default": "Data Source=.;Initial Catalog=blazorecommerce;Integrated Security=True;MultipleActiveResultSets=true;TrustServerCertificate=True"
},
"AppSettings": {
"Token": "my top secret key"
},
"JwtSettings": {
"Key": "SECRET_JWT_KEY_HERE",
"Issuer": "BlazorEcommerce.Api",
Expand Down

0 comments on commit f7b1d61

Please sign in to comment.