protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { base.ApplicationStartup(container, pipelines); // Increase size of JSON responses as 100K is way too small for a large comic collection. Make it 10M. // Also, for some reason I don't get InvalidOperationException ("Nancy.Json.JsonSettings.MaxJsonLength exceeded") // Instead Nancy generates a response with status OK and content length 0. Nancy.Json.JsonSettings.MaxJsonLength = Int32.MaxValue; Nancy.Json.JsonSettings.RetainCasing = true; // Case sensitivity is buggy in Nancy, so disable it. Or maybe I should generate/parse GUIDs correctly...... StaticConfiguration.CaseSensitive = false; StaticConfiguration.EnableRequestTracing = Database.Instance.GlobalSettings.nancy_request_tracing; if (Database.Instance.GlobalSettings.nancy_diagnostics_password == "") { DiagnosticsHook.Disable(pipelines); } // Make sure static content isn't cached, because this really messes up the ipad browsers (Atomic Browser specifically) // when the app is frequently updated. pipelines.AfterRequest.AddItemToEndOfPipeline( ctx => { ctx.Response.Headers["Cache-Control"] = "no-cache"; }); }
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { base.ApplicationStartup(container, pipelines); // We will send big JSON payloads JsonSettings.MaxJsonLength = int.MaxValue; // Authentication var authconf = new StatelessAuthenticationConfiguration(ctx => { var principal = ctx.GetFromOwinContext <ApplicationSignInManager>().AuthenticationManager.User; return(principal.Identity.IsAuthenticated ? new AuthenticatedUser(principal) : null); }); StatelessAuthentication.Enable(pipelines, authconf); #if !DEBUG // disable diagnostics in release version DiagnosticsHook.Disable(pipelines); container.Register <IDiagnostics, DisabledDiagnostics>(); StaticConfiguration.DisableErrorTraces = true; #endif pipelines.OnError += (ctx, err) => { logger.TraceEvent(TraceEventType.Error, 0, "Global application error occurred when serving request: {0}, ex: {1}", ctx.Request.Url, err); return(null); }; // make sure that we have partitions to store the coming logs var logmaintain = container.Resolve <ILogMaintenance>(); logmaintain.PerformMaintenanceIfNecessaryAsync().Wait(); }
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { base.ApplicationStartup(container, pipelines); DiagnosticsHook.Disable(pipelines); //StaticConfiguration.EnableRequestTracing = true; StaticConfiguration.Caching.EnableRuntimeViewDiscovery = true; StaticConfiguration.Caching.EnableRuntimeViewUpdates = true; #if DEBUG //pipelines.BeforeRequest.AddItemToStartOfPipeline(x => //{ // Stopwatch watch = Stopwatch.StartNew(); // x.Items.Add("timer", watch); // return null; //}); //pipelines.AfterRequest.AddItemToEndOfPipeline(x => //{ // if (!x.Items.ContainsKey("timer")) // return; // Stopwatch watch = (Stopwatch)x.Items["timer"]; // if (watch != null) // { // watch.Stop(); // //x.Trace.TraceLog.WriteLog(log => log.AppendLine(string.Format("Request took {0} ms", watch.ElapsedMilliseconds))); // Trace.WriteLine($"Request {x.Request.Url.Path} took {watch.ElapsedMilliseconds} ms"); // } //}); #endif }
/// <summary> /// Overrides the default application startup to add custom error /// handlers for Nancy. /// </summary> /// <param name="container">The TinyIoC container</param> /// <param name="pipelines">The application pipelines</param> protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { base.ApplicationStartup(container, pipelines); CustomErrorsLoader.AddCode(404, "The resource could not be found"); CustomErrorsLoader.AddCode(500, "An application error occurred"); if (CoreContainer.Instance.Settings.Core.API.Nancy.DashboardEnabled == false) { DiagnosticsHook.Disable(pipelines); // Workaround according to https://github.com/NancyFx/Nancy/issues/1518 container.Register <IDiagnostics, DisabledDiagnostics>(); } StaticConfiguration.EnableRequestTracing = CoreContainer.Instance.Settings.Core.API.Nancy.EnableRequestTracing; /* * // TODO: For analysis - add these hooks * pipelines.BeforeRequest += (NancyContext ctx) => * { * Console.WriteLine("before app"); * return null; * }; * * pipelines.AfterRequest += (NancyContext ctx) => * { * Console.WriteLine("after app"); * }; */ }
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { if (!enableDiagnostics) { DiagnosticsHook.Disable(pipelines); } container.Register <ServerConfig>(config); }
protected override void ApplicationStartup(IKernel container, IPipelines pipelines) { DiagnosticsHook.Disable(pipelines); Conventions.ViewLocationConventions.Insert(0, (viewName, model, context) => string.Concat("Nancy/Views/", viewName)); EnableDebugConventions(); StaticConfiguration.DisableErrorTraces = false; }
public void Initialize(IPipelines pipelines) { DiagnosticsHook.Enable(this.diagnosticsConfiguration, pipelines, this.diagnosticProviders, this.rootPathProvider, this.requestTracing, this.configuration, this.modelBinderLocator, this.responseProcessors, this.routeSegmentConstraints, this.cultureService); }
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { Logger.Info("Starting Web Server"); if (RuntimeInfo.IsProduction) { DiagnosticsHook.Disable(pipelines); } RegisterPipelines(pipelines); container.Resolve <DatabaseTarget>().Register(); }
protected override void RequestStartup(TinyIoCContainer container, IPipelines pipelines, NancyContext context) { // Disable /_nancy diagnostics page. DiagnosticsHook.Disable(pipelines); StaticConfiguration.DisableErrorTraces = false; pipelines.AfterRequest.AddItemToEndOfPipeline(ctx => { ctx.Response.WithHeader("Access-Control-Allow-Origin", "*") .WithHeader("Access-Control-Allow-Methods", "POST,GET") .WithHeader("Access-Control-Allow-Headers", "Accept,Origin,Content-Type"); }); }
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { Logger.Info("Starting NzbDrone API"); if (RuntimeInfoBase.IsProduction) { DiagnosticsHook.Disable(pipelines); } RegisterPipelines(pipelines); container.Resolve <DatabaseTarget>().Register(); container.Resolve <IEventAggregator>().PublishEvent(new ApplicationStartedEvent()); }
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { Logger.Info("Starting NzbDrone API"); if (RuntimeInfoBase.IsProduction) { DiagnosticsHook.Disable(pipelines); } RegisterPipelines(pipelines); container.Resolve <DatabaseTarget>().Register(); container.Resolve <IEventAggregator>().PublishEvent(new ApplicationStartedEvent()); ApplicationPipelines.OnError.AddItemToEndOfPipeline((Func <NancyContext, Exception, Response>)container.Resolve <NzbDroneErrorPipeline>().HandleException); }
public void Initialize(IPipelines pipelines) { DiagnosticsHook.Enable( pipelines, this.diagnosticProviders, this.rootPathProvider, this.requestTracing, this.configuration, this.modelBinderLocator, this.responseProcessors, this.routeSegmentConstraints, this.cultureService, this.requestTraceFactory, this.routeMetadataProviders, this.textResource, this.environment); }
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { DiagnosticsHook.Disable(pipelines); //替换默认序列化方式 container.Register <ISerializer, CustomJsonNetSerializer>(); container.Register <IUserMapper, UserMapper>(); container.Register <ICacheManager, RedisCacheManager>(); container.Register <IMessageService, MessageService>(); #region 业务注入 container.Register <IUserBaseService, UserBaseService>(); #endregion 业务注入 pipelines.AfterRequest += (ctx) => { ctx.Response.Headers.Add("Access-Control-Allow-Origin", "*"); ctx.Response.Headers.Add("Access-Control-Allow-Credentials", "true"); ctx.Response.Headers.Add("Access-Control-Allow-Methods", "*"); ctx.Response.Headers.Add("Access-Control-Allow-Headers", "Content-Type,Access-Token"); ctx.Response.Headers.Add("Access-Control-Expose-Headers", "*"); }; var configuration = new StatelessAuthenticationConfiguration( nancyContext => { //返回null代码token无效或用户未认证 var token = nancyContext.Request.Headers.Authorization; var userValidator = container.Resolve <IUserMapper>(); return(!string.IsNullOrEmpty(token) ? userValidator.GetUserFromAccessToken(token) : null); } ); StatelessAuthentication.Enable(pipelines, configuration); //启用Session //CookieBasedSessions.Enable(pipelines); base.ApplicationStartup(container, pipelines); }
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { base.ApplicationStartup(container, pipelines); // Password hasher using PBKDF2 var saltedHash = new SaltedHash( _configuration.Encryption.SaltLength, _configuration.Encryption.HashLength, _configuration.Encryption.NumberOfIterations); container.Register <ISaltedHash, SaltedHash>(saltedHash); // Disable _Nancy DiagnosticsHook.Disable(pipelines); // Takes care of outputting the CSRF token to Cookies Csrf.Enable(pipelines); // Don't show errors when we are in release StaticConfiguration.DisableErrorTraces = !StaticConfiguration.IsRunningDebug; // Wire up flowing of OWIN user to a Nancy one pipelines.BeforeRequest.AddItemToStartOfPipeline(FlowPrincipal); // TODO: Remove dummy data //var user = new CloudEntity<User> //{ // PartitionKey = "*****@*****.**", // RowKey = "Manual", // Value = new User // { // Email = "*****@*****.**", // DisplayName = "David Cumps", // HashAndSalt = saltedHash.GetHashAndSaltString("admin") // } //}; //var tableClient = container.Resolve<CloudStorageAccount>().CreateCloudTableClient(); //tableClient.RetryPolicy = new NoRetry(); //var t = new TableStorageProvider(tableClient); //t.CreateTable("User"); //t.Insert("User", user); }
protected override void ApplicationStartup(ILifetimeScope applicationContainer, IPipelines pipelines) { base.ApplicationStartup(_container, pipelines); DiagnosticsHook.Disable(pipelines); }
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { RegisterDependenciesWithNancyContainer(container); DiagnosticsHook.Disable(pipelines); }
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { DiagnosticsHook.Disable(pipelines); }
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { DiagnosticsHook.Disable(pipelines); StaticConfiguration.DisableErrorTraces = false; }
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) { container.Register <IDatabaseManager, DBStateResolver>().AsSingleton(); #if !DEBUG DiagnosticsHook.Disable(pipelines); #else StaticConfiguration.EnableRequestTracing = true; #endif redisServer = new RedisServer(LogError, LogDebug, (new RedisConfig()).Address); container.Register <RedisServer>(redisServer); var serviceId = redisServer.GenerateUniqueId().Result; container.Register <IServerConfigService, WebServerConfigService>(new WebServerConfigService(redisServer, serviceId)); sessionService = container.Resolve <SessionService>(); // CSRF that uses Redis for shared token generation. Tokens currently don't expire. Csrf.Enable(pipelines, new CryptographyConfiguration( new RijndaelEncryptionProvider(new RedisBasedKeyGenerator(redisServer)), new DefaultHmacProvider(new RedisBasedKeyGenerator(redisServer))) ); pipelines.BeforeRequest.AddItemToEndOfPipeline(ctx => { var origin = ctx.Request.Headers["Origin"].FirstOrDefault(); if (origin == null) { return(null); } var matches = corsDomains.FirstOrDefault( allowed => Regex.IsMatch(origin, "^" + allowed + "$", RegexOptions.IgnoreCase)); // No matches, so let's abort. if (matches == null) { var responseJson = (Response)"CORS not allowed."; responseJson.ContentType = "application/json"; responseJson.StatusCode = HttpStatusCode.BadRequest; return(responseJson); } return(null); }); pipelines.AfterRequest.AddItemToEndOfPipeline(ctx => { var origin = ctx.Request.Headers["Origin"].FirstOrDefault(); if (origin == null) { return; } ctx.Response.Headers.Add("Access-Control-Allow-Origin", origin); ctx.Response.Headers.Add("Access-Control-Allow-Methods", "POST,GET,DELETE,PUT,OPTIONS"); ctx.Response.Headers.Add("Access-Control-Allow-Credentials", "true"); ctx.Response.Headers.Add("Access-Control-Allow-Headers", "Accept,Origin,Content-type"); ctx.Response.Headers.Add("Access-Control-Expose-Headers", "Accept,Origin,Content-type"); }); pipelines.BeforeRequest.AddItemToEndOfPipeline(ProcessSessionAuth); pipelines.OnError += (ctx, ex) => { throw ex; }; }