You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current implementation of Controller.file only works for html files as the called Giraffe code sets the ContentType: herectx.SetContentType "text/html; charset=utf-8"
Different typed files e.g. css will not work in the browser with the wrong content type set. I propose to change the implementation of Controller.file to:
let file (ctx: HttpContext) (filePath: string) (contentType: string) =
task {
let filePath =
match Path.IsPathRooted filePath with
| true -> filePath
| false ->
let fileProvider = ctx.GetWebHostEnvironment().WebRootFileProvider
let fileInfo = fileProvider.GetFileInfo(filePath)
fileInfo.PhysicalPath
ctx.Response.ContentType <- contentType
let! file = File.ReadAllBytesAsync filePath
return! ctx.WriteBytesAsync file
}
I added another extension to HttpContext: ctx.GetWebHostEnvironment(): IWebHostEnvironment = ctx.GetService()
In my testing on Azure Functions WebRootFileProvider was initially NullFileProvider but could be instantiated like this:
let webHostEnv = req.HttpContext.GetWebHostEnvironment()
webHostEnv.WebRootPath <- Path.Combine(context.FunctionAppDirectory, "public")
webHostEnv.WebRootFileProvider <- new PhysicalFileProvider(webHostEnv.WebRootPath)
Propose that an addition is also made to the Azure Function CE to enable:
The current implementation of Controller.file only works for html files as the called Giraffe code sets the ContentType:
here
ctx.SetContentType "text/html; charset=utf-8"
Different typed files e.g. css will not work in the browser with the wrong content type set. I propose to change the implementation of Controller.file to:
I added another extension to
HttpContext
:ctx.GetWebHostEnvironment(): IWebHostEnvironment = ctx.GetService()
In my testing on Azure Functions
WebRootFileProvider
was initiallyNullFileProvider
but could be instantiated like this:Propose that an addition is also made to the Azure Function CE to enable:
Which would automatically instantiate the
WebRootFileProvider
as above.The text was updated successfully, but these errors were encountered: