コード例 #1
0
        public IActionResult ImportAllBranches()
        {
            if (string.IsNullOrWhiteSpace(_repositoryOptions.Value.Secret))
            {
                Unauthorized();
            }

            if (Request.Headers["Authorization"].FirstOrDefault() == "Bearer " + _repositoryOptions.Value.Secret)
            {
                _dataImportService.ImportAllBranches();
                return(NoContent());
            }

            return(Unauthorized());
        }
コード例 #2
0
ファイル: Startup.cs プロジェクト: SampSharp/website
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IDataImportService dataImportService, IDataRepository dataRepository)
        {
#if !DEBUG
            if (dataRepository.IsEmpty)
#endif
            dataImportService.ImportAllBranches();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/__internal/error/server_error");

                app.UseHsts();
            }

            app.Use(async(ctx, next) =>
            {
                await next();

                if (ctx.Response.StatusCode == 404 && !ctx.Response.HasStarted)
                {
                    //Re-execute the request so the user gets the error page
                    string originalPath       = ctx.Request.Path.Value;
                    ctx.Items["originalPath"] = originalPath;
                    ctx.Request.Path          = "/__internal/error/not_found";
                    await next();
                }
            });

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    "home",
                    "/",
                    new
                {
                    controller = "Home",
                    action     = "Index"
                });

                routes.MapRoute(
                    "server_error",
                    "/__internal/error/server_error",
                    new
                {
                    controller = "Error",
                    action     = "ServerError"
                });

                routes.MapRoute(
                    "not_found",
                    "/__internal/error/not_found",
                    new
                {
                    controller = "Error",
                    action     = "PageNotFound"
                });

                routes.MapRoute(
                    "webhook_manual_all_branches",
                    "/webhook/all",
                    new
                {
                    controller = "WebHook",
                    action     = "ImportAllBranches"
                });

                routes.MapRoute(
                    "webhook_github",
                    "/webhook/github",
                    new
                {
                    controller = "WebHook",
                    action     = "GitHub"
                });

                routes.MapRoute(
                    "documentation",
                    "{versionOrPage?}/{*page}",
                    new
                {
                    controller = "Documentation",
                    action     = "Index"
                });
            });
        }