コード例 #1
0
        protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
        {
            Log.Debug("ApplicationStartup");

            pipelines.EnableGzipCompression(new GzipCompressionSettings()
            {
                MinimumBytes = 1024
            });
            pipelines.AddHeadersAndLogging();
            pipelines.AddRequestStashing();

            // rate-limiting - uses remote address by default, but we can extend this to include user-agent and/or
            // authenticated user if necessary
            LeakyBucketRateLimiter.Enable(pipelines, new LeakyBucketRateLimiterConfiguration
            {
                // 100 requests per minute should be plenty
                MaxNumberOfRequests = 100, RefreshRate = TimeSpan.FromMinutes(1)
            });

            // setup auth last so that rate-limited responses include authenticated user
            // (uses AddItemToStartOfPipeline() to ensure it happens before rate-limiter)
            var auth_method = Env.GetEnvironmentString("COMPUTE_AUTH_METHOD", "");

            if (auth_method == "RHINO_ACCOUNT")
            {
                pipelines.AddAuthRhinoAccount();
            }
            else if (auth_method == "API_KEY")
            {
                pipelines.AddAuthApiKey();
            }

            base.ApplicationStartup(container, pipelines);
        }
コード例 #2
0
ファイル: Frontend.cs プロジェクト: finch3d/compute.rhino3d
        protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
        {
            Log.Debug("ApplicationStartup");

            Nancy.StaticConfiguration.DisableErrorTraces = false;

            pipelines.EnableGzipCompression(new GzipCompressionSettings()
            {
                MinimumBytes = 1024
            });

            var auth_method = Env.GetEnvironmentString("COMPUTE_AUTH_METHOD", "");

            if (auth_method == "RHINO_ACCOUNT")
            {
                pipelines.AddAuthRhinoAccount();
            }
            else if (auth_method == "API_KEY")
            {
                pipelines.AddAuthApiKey();
            }
            pipelines.AddHeadersAndLogging();
            pipelines.AddRequestStashing();

            base.ApplicationStartup(container, pipelines);
        }
コード例 #3
0
 protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
 {
     // deflate all the things
     pipelines.EnableGzipCompression(new GzipCompressionSettings()
     {
         MinimumBytes = 0
     });
     base.ApplicationStartup(container, pipelines);
 }
コード例 #4
0
        protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
        {
            // Enable Compression with Settings
            var settings = new GzipCompressionSettings();

            settings.MinimumBytes = 1024;
            pipelines.EnableGzipCompression(settings);

            base.ApplicationStartup(container, pipelines);
        }
コード例 #5
0
ファイル: Bootstrapper.cs プロジェクト: GusBeare/Simple.CRUD
        //public CryptographyConfiguration Configuration { get; set; }

        protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
        {
            // Enable Compression with Default Settings
            pipelines.EnableGzipCompression();

            base.ApplicationStartup(container, pipelines);

            // enable CSRF
            Nancy.Security.Csrf.Enable(pipelines);
        }
コード例 #6
0
ファイル: Bootstrapper.cs プロジェクト: KingJ/ShokoServer
        /// <summary>
        /// This function override the RequestStartup which is used each time a request came to Nancy
        /// </summary>
        protected override void RequestStartup(TinyIoCContainer requestContainer, IPipelines pipelines,
                                               NancyContext context)
        {
            StaticConfiguration.EnableRequestTracing = true;
            var configuration =
                new StatelessAuthenticationConfiguration(nancyContext =>
            {
                //try to take "apikey" from header
                string apiKey = nancyContext.Request.Headers["apikey"].FirstOrDefault();
                if (string.IsNullOrEmpty(apiKey))
                {
                    //take out value of "apikey" from query that was pass in request and check for User
                    apiKey = (string)nancyContext.Request.Query.apikey.Value;
                }
                if (apiKey != null)
                {
                    return(UserDatabase.GetUserFromApiKey(apiKey));
                }
                else
                {
                    return(null);
                }
            });

            StaticConfiguration.DisableErrorTraces = false;
            StatelessAuthentication.Enable(pipelines, configuration);

            pipelines.OnError += (ctx, ex) => onError(ctx, ex);

            pipelines.BeforeRequest += BeforeProcessing;
            pipelines.AfterRequest  += AfterProcessing;

            #region CORS Enable

            pipelines.AfterRequest.AddItemToEndOfPipeline((ctx) =>
            {
                ctx.Response.WithHeader("Access-Control-Allow-Origin", "*")
                .WithHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS")
                .WithHeader("Access-Control-Allow-Headers", "Accept, Origin, Content-type, apikey");
            });

            #endregion

            #region Gzip compression

            GzipCompressionSettings gzipsettings = new GzipCompressionSettings
            {
                MinimumBytes = 16384 //16k
            };
            gzipsettings.MimeTypes.Add("application/xml");
            gzipsettings.MimeTypes.Add("application/json");
            pipelines.EnableGzipCompression(gzipsettings);

            #endregion
        }
コード例 #7
0
        protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
        {
            // Enable Compression with Settings
            //var settings = new GzipCompressionSettings();
            //settings.MinimumBytes = 1024;
            //settings.MimeTypes.Add("application/vnd.myexample");
            //pipelines.EnableGzipCompression(settings);

            // Enable Compression with Default Settings
            pipelines.EnableGzipCompression();

            base.ApplicationStartup(container, pipelines);
        }
コード例 #8
0
 protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
 {
     base.ApplicationStartup(container, pipelines);
     pipelines.EnableGzipCompression();
     pipelines.AfterRequest += ctx =>
     {
         ctx.Response.Headers.Add("Access-Control-Allow-Origin", "*");
         ctx.Response.Headers.Add("Access-Control-Allow-Headers", "Accept, Origin, Content-type, X-Auth-Token");
         ctx.Response.Headers.Add("Access-Control-Allow-Method", "Get, Post, Put, Delete, Options");
     };
     container.Register(new JsonSerializer
     {
         ReferenceLoopHandling      = ReferenceLoopHandling.Serialize,
         PreserveReferencesHandling = PreserveReferencesHandling.None,
         NullValueHandling          = NullValueHandling.Ignore,
         ContractResolver           = new CamelCasePropertyNamesContractResolver()
     });
 }
コード例 #9
0
ファイル: Bootstrapper.cs プロジェクト: Totopolis/monik
        protected override void ApplicationStartup(ILifetimeScope container, IPipelines pipelines)
        {
            if (Singleton != null)
            {
                throw new BootstrapperException("Duplicate");
            }

            Singleton = this;

            // No registrations should be performed in here, however you may
            // resolve things that are needed during application startup.

            // Enable Compression with Default Settings
            pipelines.EnableGzipCompression();

            var userIdentityProvider = container.Resolve <IUserIdentityProvider>();
            var configuration        = new StatelessAuthenticationConfiguration(userIdentityProvider.GetUserIdentity);

            StatelessAuthentication.Enable(pipelines, configuration);

            OnApplicationStart();
        }
コード例 #10
0
        /// <inheritdoc />
        /// <summary>
        /// This function override the RequestStartup which is used each time a request came to Nancy
        /// </summary>
        protected override void RequestStartup(TinyIoCContainer requestContainer, IPipelines pipelines,
                                               NancyContext context)
        {
            StaticConfiguration.EnableRequestTracing = true;
            var configuration =
                new StatelessAuthenticationConfiguration(nancyContext =>
            {
                // If the server isn't up yet, we can't access the db for users
                if (!(ServerState.Instance?.ServerOnline ?? false))
                {
                    return(null);
                }
                // get apikey from header
                string apiKey = nancyContext.Request.Headers["apikey"].FirstOrDefault()?.Trim();
                // if not in header
                if (string.IsNullOrEmpty(apiKey))
                {
                    // try from query string instead
                    try
                    {
                        apiKey = (string)nancyContext.Request.Query.apikey.Value;
                    }
                    catch
                    {
                        // ignore
                    }
                }
                AuthTokens auth = RepoFactory.AuthTokens.GetByToken(apiKey);
                return(auth != null
                        ? RepoFactory.JMMUser.GetByID(auth.UserID)
                        : null);
            });

            StaticConfiguration.DisableErrorTraces = false;
            StatelessAuthentication.Enable(pipelines, configuration);

            pipelines.OnError += (ctx, ex) => onError(ctx, ex);

            pipelines.BeforeRequest += BeforeProcessing;
            pipelines.AfterRequest  += AfterProcessing;

            #region CORS Enable

            pipelines.AfterRequest.AddItemToEndOfPipeline((ctx) =>
            {
                ctx.Response.WithHeader("Access-Control-Allow-Origin", "*")
                .WithHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS")
                .WithHeader("Access-Control-Allow-Headers", "Accept, Origin, Content-type, apikey");
            });

            #endregion

            #region Gzip compression

            GzipCompressionSettings gzipsettings = new GzipCompressionSettings
            {
                MinimumBytes = 16384 //16k
            };
            gzipsettings.MimeTypes.Add("application/xml");
            gzipsettings.MimeTypes.Add("application/json");
            pipelines.EnableGzipCompression(gzipsettings);

            #endregion
        }
コード例 #11
0
        /// <summary>
        /// This function override the RequestStartup which is used each time a request came to Nancy
        /// </summary>
        protected override void RequestStartup(TinyIoCContainer requestContainer, IPipelines pipelines, NancyContext context)
        {
            var configuration =
                new StatelessAuthenticationConfiguration(nancyContext =>
                {
                    //try to take "apikey" from header
                    string apiKey = nancyContext.Request.Headers["apikey"].FirstOrDefault();
                    if (string.IsNullOrEmpty(apiKey))
                    {
                        //take out value of "apikey" from query that was pass in request and check for User
                        apiKey = (string)nancyContext.Request.Query.apikey.Value;
                    }
                    if (apiKey != null)
                    {
                        return UserDatabase.GetUserFromApiKey(apiKey);
                    }
                    else
                    {
                        return null;
                    }
                });
            StaticConfiguration.DisableErrorTraces = false;
            StatelessAuthentication.Enable(pipelines, configuration);

            pipelines.OnError += (NancyContext ctx, Exception ex) => onError(ctx, ex);

            pipelines.BeforeRequest += (NancyContext ctx) => BeforeProcessing(ctx);
            pipelines.AfterRequest += (NancyContext ctx) => AfterProcessing(ctx);

            #region CORS Enable
            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");

            });
            #endregion

            #region Gzip compression
            GzipCompressionSettings gzipsettings = new GzipCompressionSettings();
            gzipsettings.MinimumBytes = 16384; //16k
            gzipsettings.MimeTypes.Add("application/xml");
            gzipsettings.MimeTypes.Add("application/json");
            pipelines.EnableGzipCompression(gzipsettings);
            #endregion
        }