F# 不显示静态文件
所以我的服务器设置非常简单。如果路径的形式为F# 不显示静态文件,f#,suave,F#,Suave,所以我的服务器设置非常简单。如果路径的形式为/article/something,则应在文件夹static中提供静态文件something.html。由于某种原因,Files.fileWeb部件显然返回了None。我在OK“File Displayed”webpart上加了一个标签,以验证情况是否属实。OK从不执行 let app = choose [ pathScan "/article/%s" (fun article ->
/article/something
,则应在文件夹static
中提供静态文件something.html
。由于某种原因,Files.file
Web部件显然返回了None
。我在OK“File Displayed”
webpart上加了一个标签,以验证情况是否属实。OK
从不执行
let app =
choose [
pathScan "/article/%s" (fun article ->
let name = sprintf "%s.html" article
Console.WriteLine name
Files.file name >=> OK "File Displayed")
]
let config =
{ defaultConfig with homeFolder = Some (Path.GetFullPath "./static") }
[<EntryPoint>]
let main args =
startWebServer config app
0
let应用程序=
选择[
路径扫描“/article/%s”(有趣的文章->
让name=sprintf“%s.html”文章
Console.WriteLine名称
Files.file name>=>确定“显示的文件”)
]
让配置=
{defaultConfig with homeFolder=Some(Path.GetFullPath./static)}
[]
让主参数=
startWebServer配置应用程序
0
有趣的是,Console.WriteLine name
行执行得非常完美,当我执行此命令时,我在控制台窗口中看到了something.html
。问题似乎是排他性地Files.file name
返回无
文件something.html
肯定存在于静态文件夹中,所以这不是问题所在
关于导致这种情况的原因,您有什么想法吗?以下是解决静态文件服务问题的一些部分
let troubleShootExtensionPart extensionToCheck :WebPart =
fun ctx ->
match extensionToCheck with
| null | "" -> ServerErrors.INTERNAL_ERROR "Extension Error not supplied, part is not set up correctly"
| x when not <| x.StartsWith "." -> ServerErrors.INTERNAL_ERROR "Extensions start with a '.', part is not set up correctly"
| _ ->
let mtm = ctx.runtime.mimeTypesMap
match mtm extensionToCheck with
| None ->
sprintf "%s is not supported by the mime types map, compose your mime type with the `defaultMimeTypesMap`" extensionToCheck
|> RequestErrors.FORBIDDEN
| Some x ->
sprintf "%s is supported and uses '%s', compression on? : %A" extensionToCheck x.name x.compression
|> OK
|> fun wp -> wp ctx
您是否验证了
File.File name
确实返回了None
?我还将检查“/static”展开的绝对路径,因为它可能与进程的工作目录相关,这取决于启动它的人和来源where@HonzaBrestan谢谢这并不是真正发生的事情,但它帮助我找到了问题所在。我正在使用Windows,所以它不喜欢我说的是“/static”
而不是“\\static”
#if DEBUG
pathScan "/checkExtension/%s" (fun name -> troubleShootExtensionPart name)
// catch all
(fun ctx -> sprintf "404, also homeFolder resolves to %s" (Path.GetFullPath ".") |> RequestErrors.NOT_FOUND |> fun wp -> wp ctx)
#endif