/// <summary> /// AngularServerMiddleware 建構子。有兩個固定參數 next 及 options。 /// </summary> /// <param name="next">傳入 AppFunc 型態之委派參數 (delegate)</param> /// <param name="options">傳入 AngularServerOptions 型態之類別</param> public AngularServerMiddleware(AppFunc next, AngularServerOptions options) { _next = next; _options = options; _innerMiddleware = new StaticFileMiddleware(next, options.FileServerOptions.StaticFileOptions); }
/// <summary> /// OWIN self-hosted web 的擴充方法。 /// </summary> /// <param name="builder">傳入 Owin.IAppBuilder 型態的界面 (interface)</param> /// <param name="rootPath">網站的根目錄,預設值為 "/"。</param> /// <param name="entryPath">網站的啟始網頁,預設值為 "/index.html"。</param> /// <returns>傳回 public static 型態的 OWIN.IAppBuilder。</returns> public static IAppBuilder UseAngularServer(this IAppBuilder builder, string rootPath = "/", string entryPath = "/index.html") { var options = new AngularServerOptions() { FileServerOptions = new FileServerOptions() { EnableDirectoryBrowsing = false, FileSystem = new PhysicalFileSystem(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, rootPath)) }, EntryPath = new PathString(entryPath) }; builder.UseDefaultFiles(options.FileServerOptions.DefaultFilesOptions); return(builder.Use(new Func <AppFunc, AppFunc>(next => new AngularServerMiddleware(next, options).Invoke))); }