public MarvelWebSocketMiddleware(RequestDelegate next, IMarvelWebSocketManager mWebSocketManager)
 {
     _next = next;
     _mWebSocketManager = mWebSocketManager;
 }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApiVersionDescriptionProvider provider, IMarvelWebSocketManager mWebSocketManager)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            //app.UseHttpsRedirection();

            var contentProvider = new FileExtensionContentTypeProvider();

            contentProvider.Mappings.Add(".exe", "application/vnd.microsoft.portable-executable"); //file ext, ContentType
            app.UseStaticFiles(new StaticFileOptions
            {
                ContentTypeProvider = contentProvider
            });

            app.UseSwagger();
            app.UseSwaggerUI(options =>
            {
                //options.SwaggerEndpoint("/swagger/v1.0/swagger.json", "The is nini API V1.0 option");
                //options.RoutePrefix = "swagger/documentation";

                foreach (var description in provider.ApiVersionDescriptions)
                {
                    options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json",
                                            description.GroupName.ToUpperInvariant());
                }
            });

            app.UseMiddleware(typeof(MarvelErrorHandlingMiddleware));

            var rwOption = new RewriteOptions();

            rwOption.AddRedirect("^$", "swagger/index.html");
            app.UseRewriter(rwOption);

            app.UseMvc();

            var webSocketOptions = new WebSocketOptions()
            {
                KeepAliveInterval = TimeSpan.FromSeconds(120),
                ReceiveBufferSize = 4 * 1024
            };

            app.UseWebSockets(webSocketOptions);
            app.Map("/ws", ab => ab.UseMiddleware <MarvelWebSocketMiddleware>(mWebSocketManager));
        }