コード例 #1
0
ファイル: Startup.cs プロジェクト: gugray/XiePinyin
        public void Configure(IApplicationBuilder app, IHostApplicationLifetime appLife)
        {
            appLife.ApplicationStopping.Register(onAppStopping);
            // Sign up to application shutdown so we can do proper cleanup
            //appLife.ApplicationStopping.Register(onApplicationStopping);
            // Static file options: inject caching info for all static files.
            StaticFileOptions sfo = new StaticFileOptions
            {
                OnPrepareResponse = (context) =>
                {
                    // For everything coming from "/files/**", disable caching
                    if (context.Context.Request.Path.Value.StartsWith("/files/"))
                    {
                        context.Context.Response.Headers["Cache-Control"] = "no-cache, no-store, must-revalidate";
                        context.Context.Response.Headers["Pragma"]        = "no-cache";
                        context.Context.Response.Headers["Expires"]       = "0";
                    }
                    // Cache everything else
                    else
                    {
                        context.Context.Response.Headers["Cache-Control"] = "private, max-age=31536000";
                        context.Context.Response.Headers["Expires"]       = DateTime.UtcNow.AddYears(1).ToString("R");
                    }
                }
            };

            // Static files (JS, CSS etc.) served directly.
            app.UseStaticFiles(sfo);

            app.UseMiddleware <ErrorHandlerMiddleware>();

            WebSocketMiddlewareOptions wsmo = new Site.WebSocketMiddlewareOptions
            {
                AllowedOrigins           = new HashSet <string>(),
                SendSegmentSize          = 4 * 1024,
                ReceivePayloadBufferSize = 4 * 1024,
            };
            var wsao = config["webSocketAllowedOrigins"];

            foreach (var x in wsao.Split(','))
            {
                wsmo.AllowedOrigins.Add(x.Trim());
            }
            app.UseWebSockets().MapWebSocketConnections("/sock", wsmo);

            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute("api-compose", "api/compose/{*query}", new { controller = "Compose", action = "Get" });
                endpoints.MapControllerRoute("api-doc", "api/doc/{action}/{*paras}", new { controller = "Document", paras = "" });
                endpoints.MapControllerRoute("api-auth", "api/auth/{action}/{*paras}", new { controller = "Auth", paras = "" });
                endpoints.MapControllerRoute("default", "{*paras}", new { controller = "Index", action = "Index", paras = "" });
                //routes.MapRoute("default", "{*paras}", new { controller = "Index", action = "Index", paras = "" });
            });
        }
コード例 #2
0
 public WebSocketMiddleware(RequestDelegate next, WebSocketMiddlewareOptions options, ConnectionManager connectionManager)
 {
     this.options = options ?? throw new ArgumentNullException(nameof(options));
     connMgr      = connectionManager ?? throw new ArgumentNullException(nameof(connectionManager));
 }
コード例 #3
0
 public static IApplicationBuilder MapWebSocketConnections(this IApplicationBuilder app,
                                                           PathString pathMatch, WebSocketMiddlewareOptions options)
 {
     if (app == null)
     {
         throw new ArgumentNullException(nameof(app));
     }
     return(app.Map(pathMatch, branchedApp => branchedApp.UseMiddleware <WebSocketMiddleware>(options)));
 }