Esempio n. 1
0
        public SampleApiServer(SampleApiServerConfig config)
        {
            _Host = WebHost.CreateDefaultBuilder()
                    .UseKestrel(options => options.ListenLocalhost(config.Port.Value))
                    .ConfigureServices(services =>
            {
                services.AddControllers();
                if (config.EnableSwagger)
                {
                    services.AddSwaggerGen(c =>
                    {
                        c.SwaggerDoc("v1", new OpenApiInfo {
                            Title = "My API", Version = "v1"
                        });
                    });
                }
            })
                    .Configure(app =>
            {
                app.UseDeveloperExceptionPage();

                app.UseRouting();
                RouteBuilder routeBuilder = new RouteBuilder(app);
                SetupRoutes(routeBuilder, config);
                IRouter routes = routeBuilder.Build();
                app.UseRouter(routes);

                if (config.EnableSwagger)
                {
                    app.UseSwagger();
                }
            })
                    .Build();
        }
Esempio n. 2
0
 private static void SetupRoutes(RouteBuilder routeBuilder, SampleApiServerConfig config)
 {
     foreach (SampleApiServerRoute route in config.Routes)
     {
         if (route.Verb == "*")
         {
             routeBuilder.MapRoute(route.Route, context => route.Execute(context));
         }
         else
         {
             routeBuilder.MapVerb(route.Verb, route.Route, context => route.Execute(context));
         }
     }
 }
Esempio n. 3
0
        public SampleApiServer(SampleApiServerConfig config)
        {
            _Host = Host.CreateDefaultBuilder()
                    .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseUrls(config.BaseAddress);
                webBuilder.Configure(app =>
                {
                    app.UseDeveloperExceptionPage();

                    app.UseRouting();
                    RouteBuilder routeBuilder = new RouteBuilder(app);
                    SetupRoutes(routeBuilder, config);
                    IRouter routes = routeBuilder.Build();
                    app.UseRouter(routes);
                });
            })
                    .Build();
        }
        public SampleApiServer(SampleApiServerConfig config)
        {
            _Host = WebHost.CreateDefaultBuilder()
                    .UseKestrel(options => options.ListenLocalhost(config.Port.Value))
                    .ConfigureServices(services =>
            {
                services.AddAuthentication()
                .AddScheme <AuthenticationSchemeOptions, SampleBearerAuthenticationScheme>(
                    SampleBearerAuthenticationScheme.SchemeName, o => { });

                services.AddControllers();
                if (config.EnableSwagger)
                {
                    services.AddSwaggerGen(c =>
                    {
                        c.SwaggerDoc("v1", new OpenApiInfo {
                            Title = "My API", Version = "v1"
                        });
                    });
                }
            })
                    .Configure(app =>
            {
                app.UseDeveloperExceptionPage();


                app.UseRouting();
                app.UseAuthorization();

                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapControllers();
                });

                if (config.EnableSwagger)
                {
                    app.UseSwagger();
                }
            })
                    .Build();
        }