예제 #1
0
        // 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, IApplicationLifetime appLifetime)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            loggerFactory.AddSerilog();
            // Ensure any buffered events are sent at shutdown
            appLifetime.ApplicationStopped.Register(Log.CloseAndFlush);

            // Server is used as an API, so we rarely need exception page
            //if (env.IsDevelopment())
            //{
            //    app.UseDeveloperExceptionPage();
            //}

            app.UseCors("AllowAnyPolicy");

            app.UseMiddleware <HttpOptionsMiddleware>();

            if (Configuration.GetValue <bool>("Simulate:Delay:Enabled"))
            {
                app.UseMiddleware <DelayMiddleware>();
            }

            if (Configuration.GetValue <bool>("Simulate:Error:Enabled"))
            {
                app.UseMiddleware <ErrorMiddleware>();
            }

            app.UseWebSockets();

            app.UseMiddleware <NotifyWebSocketMiddlerware>();
            app.UseMiddleware <WebSocketMiddleware>();

            // Authentication must be always used as we have Authorize attributes in use
            // When Authentication is turned off, special AllowAll hander is used
            app.UseAuthentication();

            var useAuthentication = Configuration.GetValue <bool>("Authentication:Enabled");

            if (useAuthentication && Configuration.GetValue <string>("Authentication:AuthenticationType") == "token")
            {
                TokenConfiguration.UseTokenProviderMiddleware(app);
            }

            app.UseDefaultFiles();
            app.UseStaticFiles();

            if (Configuration.GetValue <bool>("Caching:ETag:Enabled"))
            {
                app.UseMiddleware <ETagMiddleware>();
            }

            app.UseMiddleware <GraphQLMiddleware>(
                app.ApplicationServices.GetRequiredService <IDataStore>(),
                app.ApplicationServices.GetRequiredService <IMessageBus>(),
                useAuthentication);

            app.UseMvc();

            app.UseSwagger();

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Fake JSON API V1");
                c.SupportedSubmitMethods(SubmitMethod.Get, SubmitMethod.Head, SubmitMethod.Post, SubmitMethod.Put, SubmitMethod.Patch, SubmitMethod.Delete);
            });
        }
예제 #2
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime appLifetime)
        {
            var folder = Configuration["staticFolder"];

            app.UseDefaultFiles();

            if (string.IsNullOrEmpty(folder))
            {
                app.UseStaticFiles();
            }
            else
            {
                app.UseSpa(spa =>
                {
                    spa.ApplicationBuilder.UseSpaStaticFiles(new StaticFileOptions
                    {
                        FileProvider = new PhysicalFileProvider(folder)
                    });
                });

                // No need to define anything else as this can only be used as a SPA server
                return;
            }

            app.UseCors("AllowAnyPolicy");

            app.UseMiddleware <HttpOptionsMiddleware>();

            if (Configuration.GetValue <bool>("Simulate:Delay:Enabled"))
            {
                app.UseMiddleware <DelayMiddleware>();
            }

            if (Configuration.GetValue <bool>("Simulate:Error:Enabled"))
            {
                app.UseMiddleware <ErrorMiddleware>();
            }

            app.UseWebSockets();

            app.UseMiddleware <NotifyWebSocketMiddlerware>();
            app.UseMiddleware <WebSocketMiddleware>();

            // Authentication must be always used as we have Authorize attributes in use
            // When Authentication is turned off, special AllowAll hander is used
            app.UseAuthentication();

            var useAuthentication = Configuration.GetValue <bool>("Authentication:Enabled");

            if (useAuthentication && Configuration["Authentication:AuthenticationType"] == "token")
            {
                TokenConfiguration.UseTokenProviderMiddleware(app);
            }

            if (Configuration.GetValue <bool>("Caching:ETag:Enabled"))
            {
                app.UseMiddleware <ETagMiddleware>();
            }

            app.UseMiddleware <GraphQLMiddleware>(
                app.ApplicationServices.GetRequiredService <IDataStore>(),
                app.ApplicationServices.GetRequiredService <IMessageBus>(),
                useAuthentication);

            app.UseMvc();

            app.UseSwagger();

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Fake JSON API V1");
                c.SupportedSubmitMethods(SubmitMethod.Get, SubmitMethod.Head, SubmitMethod.Post, SubmitMethod.Put, SubmitMethod.Patch, SubmitMethod.Delete);
            });
        }