예제 #1
0
        public void GetApiClass()
        {
            var path = "/_api/test/test1";

            var api      = new ApiMiddleware(null);
            var apiClass = api.GetApiClass(path);

            Assert.AreEqual(apiClass.Class, "test");
            Assert.AreEqual(apiClass.Method, "test1");
        }
예제 #2
0
        public void ApiMiddlewareRightTest()
        {
            var amw = new ApiMiddleware();

            Assert.IsNotNull(amw);

            var result2 = amw.Get(string.Concat("https://trello.com/b/", "wiOPDS9X", ".json")).Result;

            Assert.IsInstanceOfType(result2, typeof(Trello));
        }
예제 #3
0
        public void ApiMiddlewareTest()
        {
            var amw = new ApiMiddleware();

            Assert.IsNotNull(amw);

            var result = amw.Get(string.Concat("https://trello.com/b/", "hard_error", ".json")).Result;

            Assert.IsNull(result);
        }
예제 #4
0
        public async Task <Trello> DownloadAsync()
        {
            var apiMiddleware = new ApiMiddleware();
            var apiResponse   = await apiMiddleware.Get(string.Concat("https://trello.com/b/", _trelloUrl, ".json"));

            Source = "online";
            apiResponse.LastDbUpdate = DateTime.Now;
            AddOrUpdate(apiResponse);

            return(apiResponse);
        }
예제 #5
0
파일: FilterExtention.cs 프로젝트: yuzd/Spa
        public static IApplicationBuilder UseSpa(this IApplicationBuilder app, IWebHostEnvironment env, IConfiguration configuration)
        {
            ConfigHelper._configuration  = configuration;
            ConfigHelper.ContentRootPath = env.ContentRootPath;
            ConfigHelper.WebRootPath     = env.WebRootPath;
            if (string.IsNullOrEmpty(ConfigHelper.WebRootPath))
            {
                ConfigHelper.WebRootPath = Path.Combine(ConfigHelper.ContentRootPath, "wwwroot");
            }

            ConfigHelper.BackupPath = Path.Combine(env.WebRootPath, "_backup_");

            // 对于敏感的文件不让访问
            app.UseNotAllowedFileFilter();
            // 对于内置的静态文件访问
            app.UseEmbeddedAsset();
            // 内置Admin管理页面
            app.UseEmbeddedPage("admin");
            // 内置的casbin管理页面
            app.UseEmbeddedPage("casbin");

            //内部api
            app.UseWhen(
                c =>
            {
                // 检查路由是否满足要求
                if (!ApiMiddleware.CanInvoke(c, out var route))
                {
                    return(false);
                }
                // 路由满足后检查api是否存在
                return(c.RequestServices.GetService <SpaDomain>()?.IsSpaApi(route.Item2) ?? false);
            },
                _ => _.UseMiddleware <ApiMiddleware>());

            // 扩展静态文件访问
            app.UseAllowedFileFilter();

            // 使用js引擎
            app.UseMiddleware <RenderEngineMiddleware>();

            CreateDefaultFile();

            return(app);
        }
예제 #6
0
파일: FilterExtention.cs 프로젝트: yuzd/Spa
        /// <summary>
        /// 内置管理页面路由
        /// </summary>
        /// <param name="app"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        public static IApplicationBuilder UseEmbeddedPage(this IApplicationBuilder app, string path)
        {
            var assetList = new EmbeddedAssetProvider(_pathToAssetMap);

            return(app.UseWhen(
                       c =>
            {
                var url = c.Request.Path.Value !.ToLower();
                return url.EndsWith($"spa.{path.ToLower()}");
            },
                       _ => _.Run((async context =>
            {
                var authCheck = ApiMiddleware.AuthCheck(context, path);
                if (authCheck == null)
                {
                    return;
                }

                using var webAsset = assetList.GetAsset($"/spa/asset/{path.ToLower()}/{path.ToLower()}.html");
                context.Response.ContentType = webAsset.MediaType;
                await webAsset.Stream.CopyToAsync(context.Response.Body);
            }))));
        }
 public void Init()
 {
     _middleware = new ApiMiddleware(async(next) => { });
 }