Skip to content

Commit f64da6c

Browse files
committed
Added rest endpoint support
1 parent 6b6c9da commit f64da6c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

CoreHelpers.Branding.AspNet/MiddlwareBrandingInjector.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,39 @@ public static IApplicationBuilder UseBrandingWithRequestHost(this IApplicationBu
3333

3434
return app;
3535
}
36+
37+
public static IApplicationBuilder UseBrandingOfferingRestEndpoint(this IApplicationBuilder app, string endpoint)
38+
{
39+
app.Use(async (ctx, next) =>
40+
{
41+
if (!ctx.Request.Path.HasValue || !ctx.Request.Path.Value.ToLower().Equals(endpoint.ToLower()))
42+
{
43+
44+
// next middleware
45+
await next(ctx);
46+
47+
// done
48+
return;
49+
}
50+
51+
// get the current branding
52+
var brandingStateService = ctx.RequestServices.GetRequiredService<IBrandingStateService>();
53+
if (brandingStateService == null)
54+
throw new Exception("BrandingStateService is not available");
55+
56+
// check if we have a current state
57+
if (brandingStateService.CurrentCompanyBranding == null)
58+
throw new Exception("No branding state is available");
59+
60+
// write the branding as json
61+
await ctx.Response.WriteAsJsonAsync<ICompanyBranding>(brandingStateService.CurrentCompanyBranding);
62+
63+
// done
64+
return;
65+
});
66+
67+
return app;
68+
}
3669
}
3770
}
3871

0 commit comments

Comments
 (0)