2017-12-30 20:26:35 +00:00
using System ;
using System.Collections.Generic ;
2018-03-19 02:07:36 +00:00
using System.IO ;
2017-12-30 20:26:35 +00:00
using System.Linq ;
using System.Threading.Tasks ;
2018-03-19 02:07:36 +00:00
using Bot.Rasa.Consoles ;
using DotNetToolkit.JwtHelper ;
2017-12-30 20:26:35 +00:00
using Microsoft.AspNetCore.Builder ;
using Microsoft.AspNetCore.Hosting ;
using Microsoft.Extensions.Configuration ;
using Microsoft.Extensions.DependencyInjection ;
using Microsoft.Extensions.Logging ;
using Microsoft.Extensions.Options ;
2018-03-19 02:07:36 +00:00
using Microsoft.Extensions.PlatformAbstractions ;
using Newtonsoft.Json.Serialization ;
using Swashbuckle.AspNetCore.Swagger ;
2017-12-30 20:26:35 +00:00
namespace Bot.WebStarter
{
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 )
{
2018-03-19 02:07:36 +00:00
services . AddCors ( ) ;
services . AddJwtAuth ( Configuration ) ;
2017-12-30 20:26:35 +00:00
services . AddMvc ( ) ;
2018-03-19 02:07:36 +00:00
// Add framework services.
services . AddMvc ( options = >
{
options . RespectBrowserAcceptHeader = true ;
} ) . AddJsonOptions ( options = >
{
options . SerializerSettings . Converters . Add ( new Newtonsoft . Json . Converters . StringEnumConverter ( ) ) ;
options . SerializerSettings . ContractResolver = new CamelCasePropertyNamesContractResolver ( ) ;
//options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
} ) ;
services . AddSwaggerGen ( c = >
{
c . AddSecurityDefinition ( "Bearer" , new ApiKeyScheme ( ) { In = "header" , Description = "Please insert JWT with Bearer into field" , Name = "Authorization" , Type = "apiKey" } ) ;
var info = Configuration . GetSection ( "Swagger" ) . Get < Swashbuckle . AspNetCore . Swagger . Info > ( ) ;
c . SwaggerDoc ( info . Version , info ) ;
var filePath = Path . Combine ( PlatformServices . Default . Application . ApplicationBasePath , "Bot.Rasa.RestApi.xml" ) ;
c . IncludeXmlComments ( filePath ) ;
} ) ;
2017-12-30 20:26:35 +00:00
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure ( IApplicationBuilder app , IHostingEnvironment env )
{
if ( env . IsDevelopment ( ) )
{
app . UseDeveloperExceptionPage ( ) ;
}
2018-03-19 02:07:36 +00:00
app . UseStaticFiles ( ) ;
2017-12-30 20:26:35 +00:00
2018-03-19 02:07:36 +00:00
app . UseSwagger ( ) ;
app . UseSwaggerUI ( c = >
2017-12-30 20:26:35 +00:00
{
2018-03-19 02:07:36 +00:00
c . SupportedSubmitMethods ( SubmitMethod . Get , SubmitMethod . Post , SubmitMethod . Put , SubmitMethod . Patch , SubmitMethod . Delete ) ;
c . ShowExtensions ( ) ;
c . SwaggerEndpoint ( "/swagger/v1/swagger.json" , "API v1" ) ;
c . RoutePrefix = "api" ;
} ) ;
app . UseCors ( builder = > builder . AllowAnyHeader ( ) . AllowAnyMethod ( ) . AllowAnyOrigin ( ) . AllowCredentials ( ) ) ;
app . UseAuthentication ( ) ;
app . UseMvc ( ) ;
app . UseEntityDbContext ( Configuration , env . ContentRootPath , new String [ ] { "Bot.Rasa" } ) ;
app . UseInitLoader ( ) ;
2017-12-30 20:26:35 +00:00
}
}
}