public override Task Invoke(IOwinContext context) { var path = FileSystem.MapPath(_options.BasePath, context.Request.Path.Value); var ext = Path.GetExtension(path); if (CanHandle(ext)) { Trace.WriteLine("Invoke MinifyMiddleware"); if (path.Contains(".min.")) { return(Next.Invoke(context)); } var compressed = String.Empty; context.Response.StatusCode = 200; context.Response.ContentType = MimeTypeService.GetMimeType(ext); if (ext.Equals(".css")) { compressed = CompressCSS(path); } if (ext.Equals(".js")) { compressed = CompressJs(path); } context.Response.Write(compressed); return(Globals.CompletedTask); } return(Next.Invoke(context)); }
public override Task Invoke(IOwinContext context) { var path = FileSystem.MapPath(_options.BasePath, context.Request.Path.Value); var ext = Path.GetExtension(path); if (CanHandle(ext)) { Trace.WriteLine("Invoke LessMiddleware"); context.Response.StatusCode = 200; context.Response.ContentType = MimeTypeService.GetMimeType(".css"); var rawLess = File.ReadAllText(path); var compressed = Less.Parse(rawLess, new DotlessConfiguration { MinifyOutput = true }); context.Response.Write(compressed); return(Globals.CompletedTask); } return(Next.Invoke(context)); }
public override Task Invoke(IOwinContext context) { var path = FileSystem.MapPath(_options.BasePath, context.Request.Path.Value); var ext = Path.GetExtension(path); if (CanHandle(ext)) { Trace.WriteLine("Invoke RazorMiddleware"); context.Response.StatusCode = 200; context.Response.ContentType = MimeTypeService.GetMimeType(".html"); var dynamicViewBag = new DynamicViewBag(); dynamicViewBag.AddValue("Options", _options); var razor = File.ReadAllText(path); var result = Razor.Parse(razor, null, dynamicViewBag, String.Empty); context.Response.Write(result); return(Globals.CompletedTask); } return(Next.Invoke(context)); }
public override Task Invoke(IOwinContext context) { Trace.WriteLine("Invoke DefaultMiddleware"); var path = FileSystem.MapPath(_options.BasePath, context.Request.Path.Value); context.Response.StatusCode = 200; context.Response.ContentType = MimeTypeService.GetMimeType(Path.GetExtension(path)); using (var inputStream = new FileStream(path, FileMode.Open, FileAccess.Read)) { StreamHandler.CopyStream(context.Response.Body, inputStream); } return(Globals.CompletedTask); }
public override Task Invoke(IOwinContext context) { var path = FileSystem.MapPath(_options.BasePath, context.Request.Path.Value); var ext = Path.GetExtension(path); if (ExtToHandle(ext)) { Trace.WriteLine("Invoke SassMiddleware"); context.Response.StatusCode = 200; context.Response.ContentType = MimeTypeService.GetMimeType(".css"); var compiler = new SassCompiler(); var compressed = compiler.CompileFile(path, OutputStyle.Compressed, false); compressed = compressed.Replace(";}", "}").Replace(" {", "{"); context.Response.Write(compressed); return(Globals.CompletedTask); } return(Next.Invoke(context)); }