97 lines
3.3 KiB
C#
97 lines
3.3 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using Microsoft.AspNetCore.Builder;
|
|||
|
using Microsoft.AspNetCore.Hosting;
|
|||
|
using Microsoft.AspNetCore.Http;
|
|||
|
using Microsoft.Extensions.Configuration;
|
|||
|
using Microsoft.Extensions.DependencyInjection;
|
|||
|
using Microsoft.Extensions.Logging;
|
|||
|
using Microsoft.Extensions.Options;
|
|||
|
using PurchaseBff.Filters.Basket.API.Infrastructure.Filters;
|
|||
|
using Swashbuckle.AspNetCore.Swagger;
|
|||
|
|
|||
|
namespace PurchaseBff
|
|||
|
{
|
|||
|
public class Startup
|
|||
|
{
|
|||
|
public Startup(IConfiguration configuration)
|
|||
|
{
|
|||
|
Configuration = configuration;
|
|||
|
}
|
|||
|
|
|||
|
public IConfiguration Configuration { get; }
|
|||
|
|
|||
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|||
|
public void ConfigureServices(IServiceCollection services)
|
|||
|
{
|
|||
|
services.AddMvc();
|
|||
|
|
|||
|
services.AddSwaggerGen(options =>
|
|||
|
{
|
|||
|
options.DescribeAllEnumsAsStrings();
|
|||
|
options.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info
|
|||
|
{
|
|||
|
Title = "Purchase BFF API Gateway",
|
|||
|
Version = "v1",
|
|||
|
Description = "BFF API Gateway for Purchase features",
|
|||
|
TermsOfService = "Terms Of Service"
|
|||
|
});
|
|||
|
|
|||
|
options.AddSecurityDefinition("oauth2", new OAuth2Scheme
|
|||
|
{
|
|||
|
Type = "oauth2",
|
|||
|
Flow = "implicit",
|
|||
|
AuthorizationUrl = $"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/authorize",
|
|||
|
TokenUrl = $"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/token",
|
|||
|
Scopes = new Dictionary<string, string>()
|
|||
|
{
|
|||
|
{ "purchasebff", "Purchase BFF API Gateway" }
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
options.OperationFilter<AuthorizeCheckOperationFilter>();
|
|||
|
});
|
|||
|
|
|||
|
services.AddCors(options =>
|
|||
|
{
|
|||
|
options.AddPolicy("CorsPolicy",
|
|||
|
builder => builder.AllowAnyOrigin()
|
|||
|
.AllowAnyMethod()
|
|||
|
.AllowAnyHeader()
|
|||
|
.AllowCredentials());
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|||
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
|||
|
{
|
|||
|
|
|||
|
var pathBase = Configuration["PATH_BASE"];
|
|||
|
if (!string.IsNullOrEmpty(pathBase))
|
|||
|
{
|
|||
|
loggerFactory.CreateLogger("init").LogDebug($"Using PATH BASE '{pathBase}'");
|
|||
|
app.UsePathBase(pathBase);
|
|||
|
}
|
|||
|
|
|||
|
app.UseCors("CorsPolicy");
|
|||
|
|
|||
|
if (env.IsDevelopment())
|
|||
|
{
|
|||
|
app.UseDeveloperExceptionPage();
|
|||
|
}
|
|||
|
|
|||
|
app.UseMvc();
|
|||
|
|
|||
|
app.UseSwagger().UseSwaggerUI(c =>
|
|||
|
{
|
|||
|
c.SwaggerEndpoint($"{ (!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty) }/swagger/v1/swagger.json", "Purchase BFF V1");
|
|||
|
c.ConfigureOAuth2("purchasebffwaggerui", "", "", "Purchase BFF Swagger UI");
|
|||
|
});
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|