public Task ServerSideSetup(NetworkAccessServer server) { FileSystem = server.FileSystem; Serializer = server.Serializer; return(Task.CompletedTask); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } app.UseHttpsRedirection(); app.UseMvc(); app.UseWebSockets(new WebSocketOptions() { }); app.Use(async(context, next) => { string[] path = context.Request.Path.Value.Split('/').Where(x => !string.IsNullOrWhiteSpace(x)).ToArray(); ulong key; if (path.Length >= 2 && path[0] == "files" && ulong.TryParse(path[1], out key)) { if (context.WebSockets.IsWebSocketRequest) { NetworkAccessServer networkAccessServer = NetworkAccessServer.NewTracked(key, () => context.WebSockets.AcceptWebSocketAsync()); if (networkAccessServer == null) { context.Response.StatusCode = 423; } else { await networkAccessServer.StartAsync(); } } else { context.Response.StatusCode = 400; } } else { await next(); } }); }