Beispiel #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.Use(async(context, next) =>
            {
                context.Response.Headers.Add("hostname", context.Request.Host.Value);
                context.Response.ContentType = "text/html; charset=UTF-8";
                await next.Invoke();
            });

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGet("/", async context =>
                {
                    await context.Response.WriteAsync("Hello Worl111d!");
                });
                endpoints.MapGet("/incamp18-quote", async context =>
                {
                    var requestService = SetRequestService(context);
                    try
                    {
                        await requestService.PerformRequest(networkConfig.GetUrls());
                    }
                    catch (HttpRequestException e)
                    {
                        await context.Response.WriteAsync(e.Message);
                    }
                });
                endpoints.MapGet("/who", async context =>
                {
                    await context.Response.WriteAsync(DataStorage.who.GetRandomElement());
                });

                endpoints.MapGet("/does", async context =>
                {
                    await context.Response.WriteAsync(DataStorage.does.GetRandomElement());
                });
                endpoints.MapGet("/what", async context =>
                {
                    await context.Response.WriteAsync(DataStorage.what.GetRandomElement());
                });
                endpoints.MapGet("/how", async context =>
                {
                    await context.Response.WriteAsync(DataStorage.how.GetRandomElement());
                });
                endpoints.MapGet("/quote", async context =>
                {
                    await context.Response.WriteAsync(new Quote().GenerateQuote());
                });
            });
        }