Fix Failing middleware and move it to Basket.api
This commit is contained in:
parent
bf34bff8dd
commit
f39fdb92ca
@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ordering.API.Infrastructure.Middlewares
|
||||
namespace Basket.API.Infrastructure.Middlewares
|
||||
{
|
||||
public static class FailingMiddlewareAppBuilderExtensions
|
||||
{
|
@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ordering.API.Infrastructure.Middlewares
|
||||
namespace Basket.API.Infrastructure.Middlewares
|
||||
{
|
||||
public class FailingMiddleware
|
||||
{
|
||||
@ -26,8 +26,7 @@ namespace Ordering.API.Infrastructure.Middlewares
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (_mustFail)
|
||||
if (MustFail(context))
|
||||
{
|
||||
context.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
|
||||
context.Response.ContentType = "text/plain";
|
||||
@ -42,7 +41,7 @@ namespace Ordering.API.Infrastructure.Middlewares
|
||||
private async Task ProcessConfigRequest(HttpContext context)
|
||||
{
|
||||
var enable = context.Request.Query.Keys.Any(k => k == "enable");
|
||||
var disable = context.Request.Query.Keys.Any(k => k == "disable");
|
||||
var disable = context.Request.Query.Keys.Any(k => k == "disable");
|
||||
|
||||
if (enable && disable)
|
||||
{
|
||||
@ -74,5 +73,11 @@ namespace Ordering.API.Infrastructure.Middlewares
|
||||
await context.Response.WriteAsync(message);
|
||||
}
|
||||
|
||||
private bool MustFail(HttpContext context)
|
||||
{
|
||||
return _mustFail &&
|
||||
(_options.EndpointPaths.Any(x => x == context.Request.Path.Value)
|
||||
|| _options.EndpointPaths.Count == 0);
|
||||
}
|
||||
}
|
||||
}
|
@ -3,10 +3,11 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ordering.API.Infrastructure.Middlewares
|
||||
namespace Basket.API.Infrastructure.Middlewares
|
||||
{
|
||||
public class FailingOptions
|
||||
{
|
||||
public string ConfigPath = "/Failing";
|
||||
public List<string> EndpointPaths { get; set; } = new List<string>();
|
||||
}
|
||||
}
|
@ -1,23 +1,22 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ordering.API.Infrastructure.Middlewares
|
||||
namespace Basket.API.Infrastructure.Middlewares
|
||||
{
|
||||
public class FailingStartupFilter : IStartupFilter
|
||||
{
|
||||
public FailingStartupFilter()
|
||||
private readonly Action<FailingOptions> _options;
|
||||
public FailingStartupFilter(Action<FailingOptions> optionsAction)
|
||||
{
|
||||
_options = optionsAction;
|
||||
}
|
||||
|
||||
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
|
||||
{
|
||||
return app =>
|
||||
{
|
||||
app.UseFailingMiddleware();
|
||||
app.UseFailingMiddleware(_options);
|
||||
next(app);
|
||||
};
|
||||
}
|
@ -1,23 +1,18 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Ordering.API.Infrastructure.Middlewares;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.AspNetCore.Hosting
|
||||
namespace Basket.API.Infrastructure.Middlewares
|
||||
{
|
||||
public static class WebHostBuildertExtensions
|
||||
{
|
||||
public static IWebHostBuilder UseFailing(this IWebHostBuilder builder, string path)
|
||||
public static IWebHostBuilder UseFailing(this IWebHostBuilder builder, Action<FailingOptions> options)
|
||||
{
|
||||
builder.ConfigureServices(services =>
|
||||
{
|
||||
services.AddSingleton<IStartupFilter>(new FailingStartupFilter());
|
||||
services.AddSingleton<IStartupFilter>(new FailingStartupFilter(options));
|
||||
});
|
||||
return builder;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Basket.API.Infrastructure.Middlewares;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Basket.API
|
||||
@ -10,6 +12,12 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
||||
{
|
||||
var host = new WebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseFailing(options =>
|
||||
{
|
||||
options.ConfigPath = "/Failing";
|
||||
options.EndpointPaths = new List<string>()
|
||||
{ "/api/v1/basket/checkout", "/hc" };
|
||||
})
|
||||
.UseHealthChecks("/hc")
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseIISIntegration()
|
||||
|
@ -10,7 +10,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API
|
||||
{
|
||||
var host = new WebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseFailing("/Failing")
|
||||
.UseHealthChecks("/hc")
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseIISIntegration()
|
||||
|
@ -56,7 +56,7 @@ namespace Microsoft.eShopOnContainers.WebMVC.Controllers
|
||||
{
|
||||
ModelState.AddModelError("Error", "It was not possible to create a new order, please try later on. (Business Msg Due to Circuit-Breaker)");
|
||||
}
|
||||
return View(model);
|
||||
return View("Create", model);
|
||||
}
|
||||
|
||||
public async Task<IActionResult> Cancel(string orderId)
|
||||
|
@ -6,6 +6,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Polly.CircuitBreaker;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.WebMVC.ViewComponents
|
||||
{
|
||||
@ -17,11 +18,20 @@ namespace Microsoft.eShopOnContainers.WebMVC.ViewComponents
|
||||
|
||||
public async Task<IViewComponentResult> InvokeAsync(ApplicationUser user)
|
||||
{
|
||||
var itemsInCart = await ItemsInCartAsync(user);
|
||||
var vm = new CartComponentViewModel()
|
||||
var vm = new CartComponentViewModel();
|
||||
try
|
||||
{
|
||||
ItemsCount = itemsInCart
|
||||
};
|
||||
var itemsInCart = await ItemsInCartAsync(user);
|
||||
vm.ItemsCount = itemsInCart;
|
||||
return View(vm);
|
||||
}
|
||||
catch (BrokenCircuitException)
|
||||
{
|
||||
// Catch error when Basket.api is in circuit-opened mode
|
||||
ViewBag.IsBasketInoperative = true;
|
||||
vm.ItemsCount = 0;
|
||||
}
|
||||
|
||||
return View(vm);
|
||||
}
|
||||
private async Task<int> ItemsInCartAsync(ApplicationUser user)
|
||||
|
@ -8,13 +8,21 @@
|
||||
asp-area=""
|
||||
asp-controller="Cart"
|
||||
asp-action="Index">
|
||||
|
||||
<div class="esh-basketstatus-image">
|
||||
<img src="~/images/cart.png" />
|
||||
</div>
|
||||
<div class="esh-basketstatus-badge">
|
||||
@Model.ItemsCount
|
||||
</div>
|
||||
@if (ViewBag.IsBasketInoperative == true)
|
||||
{
|
||||
<div class="esh-basketstatus-badge-inoperative">
|
||||
@Model.ItemsCount
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="esh-basketstatus-badge">
|
||||
@Model.ItemsCount
|
||||
</div>
|
||||
}
|
||||
</a>
|
||||
|
||||
|
||||
|
@ -11,6 +11,13 @@ $color-secondary-darker: darken($color-secondary, 20%);
|
||||
$color-secondary-bright: lighten($color-secondary, 10%);
|
||||
$color-secondary-brighter: lighten($color-secondary, 20%);
|
||||
|
||||
$color-warning: #ff0000;
|
||||
$color-warning-dark: darken($color-warning, 5%);
|
||||
$color-warning-darker: darken($color-warning, 20%);
|
||||
$color-warning-bright: lighten($color-warning, 10%);
|
||||
$color-warning-brighter: lighten($color-warning, 20%);
|
||||
|
||||
|
||||
$color-background-dark: #333333;
|
||||
$color-background-darker: #000000;
|
||||
$color-background-bright: #EEEEFF;
|
||||
|
1
src/Web/WebMVC/wwwroot/css/app.component.min.css
vendored
Normal file
1
src/Web/WebMVC/wwwroot/css/app.component.min.css
vendored
Normal file
@ -0,0 +1 @@
|
||||
.esh-app-footer{background-color:#000;border-top:1px solid #eee;margin-top:2.5rem;padding-bottom:2.5rem;padding-top:2.5rem;width:100%;}.esh-app-footer-brand{height:50px;width:230px;}
|
@ -31,6 +31,21 @@
|
||||
width: 1.5rem;
|
||||
}
|
||||
|
||||
.esh-basketstatus-badge-inoperative {
|
||||
background-color: #ff0000;
|
||||
border-radius: 50%;
|
||||
color: #FFFFFF;
|
||||
display: block;
|
||||
height: 1.5rem;
|
||||
left: 50%;
|
||||
position: absolute;
|
||||
text-align: center;
|
||||
top: 0;
|
||||
transform: translateX(-38%);
|
||||
transition: all 0.35s;
|
||||
width: 1.5rem;
|
||||
}
|
||||
|
||||
.esh-basketstatus:hover .esh-basketstatus-badge {
|
||||
background-color: transparent;
|
||||
color: #75b918;
|
||||
|
1
src/Web/WebMVC/wwwroot/css/basket/basket-status/basket-status.component.min.css
vendored
Normal file
1
src/Web/WebMVC/wwwroot/css/basket/basket-status/basket-status.component.min.css
vendored
Normal file
@ -0,0 +1 @@
|
||||
.esh-basketstatus{cursor:pointer;display:inline-block;float:right;position:relative;transition:all .35s;}.esh-basketstatus.is-disabled{opacity:.5;pointer-events:none;}.esh-basketstatus-image{height:36px;margin-top:.5rem;}.esh-basketstatus-badge{background-color:#83d01b;border-radius:50%;color:#fff;display:block;height:1.5rem;left:50%;position:absolute;text-align:center;top:0;transform:translateX(-38%);transition:all .35s;width:1.5rem;}.esh-basketstatus-badge-inoperative{background-color:#f00;border-radius:50%;color:#fff;display:block;height:1.5rem;left:50%;position:absolute;text-align:center;top:0;transform:translateX(-38%);transition:all .35s;width:1.5rem;}.esh-basketstatus:hover .esh-basketstatus-badge{background-color:transparent;color:#75b918;transition:all .35s;}
|
@ -33,6 +33,22 @@
|
||||
width: $size;
|
||||
}
|
||||
|
||||
&-badge-inoperative {
|
||||
$size: 1.5rem;
|
||||
background-color: $color-warning;
|
||||
border-radius: 50%;
|
||||
color: $color-foreground-brighter;
|
||||
display: block;
|
||||
height: $size;
|
||||
left: 50%;
|
||||
position: absolute;
|
||||
text-align: center;
|
||||
top: 0;
|
||||
transform: translateX(-38%);
|
||||
transition: all $animation-speed-default;
|
||||
width: $size;
|
||||
}
|
||||
|
||||
&:hover &-badge {
|
||||
background-color: transparent;
|
||||
color: $color-secondary-dark;
|
||||
|
1
src/Web/WebMVC/wwwroot/css/basket/basket.component.min.css
vendored
Normal file
1
src/Web/WebMVC/wwwroot/css/basket/basket.component.min.css
vendored
Normal file
@ -0,0 +1 @@
|
||||
.esh-basket{min-height:80vh;}.esh-basket-titles{padding-bottom:1rem;padding-top:2rem;}.esh-basket-titles--clean{padding-bottom:0;padding-top:0;}.esh-basket-title{text-transform:uppercase;}.esh-basket-items--border{border-bottom:1px solid #eee;padding:.5rem 0;}.esh-basket-items--border:last-of-type{border-color:transparent;}.esh-basket-items-margin-left1{margin-left:1px;}.esh-basket-item{font-size:1rem;font-weight:300;}.esh-basket-item--middle{line-height:8rem;}@media screen and (max-width:1024px){.esh-basket-item--middle{line-height:1rem;}}.esh-basket-item--mark{color:#00a69c;}.esh-basket-image{height:8rem;}.esh-basket-input{line-height:1rem;width:100%;}.esh-basket-checkout{background-color:#83d01b;border:0;border-radius:0;color:#fff;display:inline-block;font-size:1rem;font-weight:400;margin-top:1rem;padding:1rem 1.5rem;text-align:center;text-transform:uppercase;transition:all .35s;}.esh-basket-checkout:hover{background-color:#4a760f;transition:all .35s;}
|
1
src/Web/WebMVC/wwwroot/css/catalog/catalog.component.min.css
vendored
Normal file
1
src/Web/WebMVC/wwwroot/css/catalog/catalog.component.min.css
vendored
Normal file
@ -0,0 +1 @@
|
||||
.esh-catalog-hero{background-image:url("../../images/main_banner.png");background-size:cover;height:260px;width:100%;}.esh-catalog-title{position:relative;top:74.28571px;}.esh-catalog-filters{background-color:#00a69c;height:65px;}.esh-catalog-filter{-webkit-appearance:none;background-color:transparent;border-color:#00d9cc;color:#fff;cursor:pointer;margin-right:1rem;margin-top:.5rem;min-width:140px;outline-color:#83d01b;padding-bottom:0;padding-left:.5rem;padding-right:.5rem;padding-top:1.5rem;}.esh-catalog-filter option{background-color:#00a69c;}.esh-catalog-label{display:inline-block;position:relative;z-index:0;}.esh-catalog-label::before{color:rgba(255,255,255,.5);content:attr(data-title);font-size:.65rem;margin-left:.5rem;margin-top:.65rem;position:absolute;text-transform:uppercase;z-index:1;}.esh-catalog-label::after{background-image:url("../../images/arrow-down.png");content:'';height:7px;position:absolute;right:1.5rem;top:2.5rem;width:10px;z-index:1;}.esh-catalog-send{background-color:#83d01b;color:#fff;cursor:pointer;font-size:1rem;margin-top:-1.5rem;padding:.5rem;transition:all .35s;}.esh-catalog-send:hover{background-color:#4a760f;transition:all .35s;}.esh-catalog-items{margin-top:1rem;}.esh-catalog-item{margin-bottom:1.5rem;text-align:center;width:33%;display:inline-block;float:none !important;}@media screen and (max-width:1024px){.esh-catalog-item{width:50%;}}@media screen and (max-width:768px){.esh-catalog-item{width:100%;}}.esh-catalog-thumbnail{max-width:370px;width:100%;}.esh-catalog-button{background-color:#83d01b;border:0;color:#fff;cursor:pointer;font-size:1rem;height:3rem;margin-top:1rem;transition:all .35s;width:80%;}.esh-catalog-button.is-disabled{opacity:.5;pointer-events:none;}.esh-catalog-button:hover{background-color:#4a760f;transition:all .35s;}.esh-catalog-name{font-size:1rem;font-weight:300;margin-top:.5rem;text-align:center;text-transform:uppercase;}.esh-catalog-price{font-size:28px;font-weight:900;text-align:center;}.esh-catalog-price::before{content:'$';}
|
1
src/Web/WebMVC/wwwroot/css/orders/orders-detail/orders-detail.component.min.css
vendored
Normal file
1
src/Web/WebMVC/wwwroot/css/orders/orders-detail/orders-detail.component.min.css
vendored
Normal file
@ -0,0 +1 @@
|
||||
.esh-orders_detail{min-height:80vh;}.esh-orders_detail-section{padding:1rem 0;}.esh-orders_detail-section--right{text-align:right;}.esh-orders_detail-titles{padding-bottom:1rem;padding-top:2rem;}.esh-orders_detail-title{text-transform:uppercase;}.esh-orders_detail-items--border{border-bottom:1px solid #eee;padding:.5rem 0;}.esh-orders_detail-items--border:last-of-type{border-color:transparent;}.esh-orders_detail-item{font-size:1rem;font-weight:300;}.esh-orders_detail-item--middle{line-height:8rem;}@media screen and (max-width:768px){.esh-orders_detail-item--middle{line-height:1rem;}}.esh-orders_detail-item--mark{color:#83d01b;}.esh-orders_detail-image{height:8rem;}
|
1
src/Web/WebMVC/wwwroot/css/orders/orders-new/orders-new.component.min.css
vendored
Normal file
1
src/Web/WebMVC/wwwroot/css/orders/orders-new/orders-new.component.min.css
vendored
Normal file
@ -0,0 +1 @@
|
||||
.esh-orders_new{min-height:80vh;}.esh-orders_new-header{background-color:#00a69c;height:4rem;}.esh-orders_new-back{color:rgba(255,255,255,.4);line-height:4rem;text-decoration:none;text-transform:uppercase;transition:color .35s;}.esh-orders_new-back:hover{color:#fff;transition:color .35s;}.esh-orders_new-section{padding:1rem 0;}.esh-orders_new-section--right{text-align:right;}.esh-orders_new-placeOrder{background-color:#83d01b;border:0;border-radius:0;color:#fff;display:inline-block;font-size:1rem;font-weight:400;margin-top:1rem;padding:1rem 1.5rem;text-align:center;text-transform:uppercase;transition:all .35s;}.esh-orders_new-placeOrder:hover{background-color:#4a760f;transition:all .35s;}.esh-orders_new-titles{padding-bottom:1rem;padding-top:2rem;}.esh-orders_new-title{font-size:1.25rem;text-transform:uppercase;}.esh-orders_new-items--border{border-bottom:1px solid #eee;padding:.5rem 0;}.esh-orders_new-items--border:last-of-type{border-color:transparent;}.esh-orders_new-item{font-size:1rem;font-weight:300;}.esh-orders_new-item--middle{line-height:8rem;}@media screen and (max-width:768px){.esh-orders_new-item--middle{line-height:1rem;}}.esh-orders_new-item--mark{color:#83d01b;}.esh-orders_new-image{height:8rem;}.esh-orders_new-alert{margin-top:10px;}
|
1
src/Web/WebMVC/wwwroot/css/orders/orders.component.min.css
vendored
Normal file
1
src/Web/WebMVC/wwwroot/css/orders/orders.component.min.css
vendored
Normal file
@ -0,0 +1 @@
|
||||
.esh-orders{min-height:80vh;overflow-x:hidden;}.esh-orders-header{background-color:#00a69c;height:4rem;}.esh-orders-back{color:rgba(255,255,255,.4);line-height:4rem;text-decoration:none;text-transform:uppercase;transition:color .35s;}.esh-orders-back:hover{color:#fff;transition:color .35s;}.esh-orders-titles{padding-bottom:1rem;padding-top:2rem;}.esh-orders-title{text-transform:uppercase;}.esh-orders-items{height:2rem;line-height:2rem;position:relative;}.esh-orders-items:nth-of-type(2n+1):before{background-color:#eef;content:'';height:100%;left:0;margin-left:-100vw;position:absolute;top:0;width:200vw;z-index:-1;}.esh-orders-item{font-weight:300;}.esh-orders-item--hover{opacity:0;pointer-events:none;}.esh-orders-items:hover .esh-orders-item--hover{opacity:1;pointer-events:all;}.esh-orders-link{color:#83d01b;text-decoration:none;transition:color .35s;}.esh-orders-link:hover{color:#75b918;transition:color .35s;}
|
1
src/Web/WebMVC/wwwroot/css/shared/components/header/header.min.css
vendored
Normal file
1
src/Web/WebMVC/wwwroot/css/shared/components/header/header.min.css
vendored
Normal file
@ -0,0 +1 @@
|
||||
.esh-header{background-color:#00a69c;height:4rem;}.esh-header-back{color:rgba(255,255,255,.5);line-height:4rem;text-decoration:none;text-transform:uppercase;transition:color .35s;}.esh-header-back:hover{color:#fff;transition:color .35s;}
|
1
src/Web/WebMVC/wwwroot/css/shared/components/pager/pager.min.css
vendored
Normal file
1
src/Web/WebMVC/wwwroot/css/shared/components/pager/pager.min.css
vendored
Normal file
@ -0,0 +1 @@
|
||||
.esh-pager-wrapper{padding-top:1rem;text-align:center;}.esh-pager-item{margin:0 5vw;}.esh-pager-item.is-disabled{opacity:0;pointer-events:none;}.esh-pager-item--navigable{cursor:pointer;display:inline-block;}.esh-pager-item--navigable:hover{color:#83d01b;}@media screen and (max-width:1280px){.esh-pager-item{font-size:.85rem;}}@media screen and (max-width:1024px){.esh-pager-item{margin:0 2.5vw;}}
|
Loading…
x
Reference in New Issue
Block a user