F# Can';t让WebSharperJavaScript客户端在Suave上运行
我正在试用下一页标题为“添加客户端功能”的示例代码段: 它看起来有点过时,并且不能按原样编译,因此基于代码被截取的原始存储库,这就是我现在拥有的F# Can';t让WebSharperJavaScript客户端在Suave上运行,f#,websharper,websharper.ui.next,F#,Websharper,Websharper.ui.next,我正在试用下一页标题为“添加客户端功能”的示例代码段: 它看起来有点过时,并且不能按原样编译,因此基于代码被截取的原始存储库,这就是我现在拥有的 namespace TestSuaveWs open WebSharper open WebSharper.Sitelets open WebSharper.UI open WebSharper.UI.Html open WebSharper.UI.Client module Server = [<Rpc>] let
namespace TestSuaveWs
open WebSharper
open WebSharper.Sitelets
open WebSharper.UI
open WebSharper.UI.Html
open WebSharper.UI.Client
module Server =
[<Rpc>]
let DoWork (s: string) =
async {
return System.String(List.ofSeq s |> List.rev |> Array.ofList)
}
[<JavaScript>]
module Client =
open WebSharper.JavaScript
open WebSharper.Html.Client
let Main () =
let input = Input [ Attr.Value "" ]
let output = H1 []
Div [
input
Button [ Text "Send" ]
|>! OnClick (fun _ _ ->
async {
let! data = Server.DoWork input.Value
output.Text <- data
}
|> Async.Start
)
HR []
H4 [ Class "text-muted" ] -- Text "The server responded:"
Div [ Class "jumbotron" ] -< [ output ]
]
module TheSite =
open WebSharper.UI.Server
[<Website>]
let MySite =
Application.SinglePage (fun ctx ->
Content.Page(
Body = [
h1 [] [ text "Say Hi to the server" ]
div [] [ client <@ Client.Main() @> ]
]
)
)
open global.Suave
open Suave.Web
open WebSharper.Suave
let webPart = WebSharperAdapter.ToWebPart(MySite, RootDirectory="../..")
名称空间TestSuaveWs
开放式Web服务器
打开WebSharper.Sitelets
打开WebSharper.UI
打开webharper.UI.Html
打开webharper.UI.Client
模块服务器=
[]
让道具(s:细绳)=
异步的{
返回System.String(List.ofSeq s |>List.rev |>Array.ofList)
}
[]
模块客户端=
打开WebSharper.JavaScript
打开webharper.Html.Client
让Main()=
让输入=输入[Attr.Value”“]
让输出=H1[]
Div[
输入
按钮[文本“发送”]
|>!OnClick(有趣的)
异步的{
让!data=Server.DoWork input.Value
output.Text Async.Start
)
HR[]
H4[类“文本静音”]--文本“服务器响应:”
Div[类别“jumbotron”]-<[输出]
]
模块站点=
打开webharper.UI.Server
[]
让MySite=
Application.SinglePage(趣味ctx->
内容页(
正文=[
h1[]文本“向服务器问好”]
部门[][客户]
]
)
)
开放全球,温文尔雅
打开Suave.Web
打开WebSharper.Suave
让webPart=WebSharperAdapter.TowerPart(MySite,RootDirectory=“../…”)
然后是主程序
namespace TestSuaveWs
module Main =
open System
open System.Threading
open Suave
[<EntryPoint>]
let main argv =
let cts = new CancellationTokenSource()
let conf = { defaultConfig with cancellationToken = cts.Token }
let listening, server = startWebServerAsync conf TheSite.webPart
Async.Start(server, cts.Token)
printfn "Make requests now"
Console.ReadKey true |> ignore
cts.Cancel()
0
名称空间TestSuaveWs
主模块=
开放系统
开放系统。线程
开放文雅
[]
让主argv=
设cts=new CancellationTokenSource()
让conf={defaultConfig with cancellationToken=cts.Token}
让我们监听,server=startwebserver异步conf TheSite.webPart
Async.Start(服务器,cts.Token)
printfn“立即提出请求”
Console.ReadKey true |>忽略
cts.Cancel()
0
程序运行时,我可以在localhost:8080上看到文本“向服务器问好”,但该文本下没有任何内容。页面上带有示例的图片显示了它应该是什么样子。应该有一个文本输入字段、一个按钮和一个回复文本
当我在Chrome浏览器中打开Developer Tools时,我可以看到有一堆类似的消息,只是javascript文件名不同,上面写着“加载资源失败:服务器响应状态为404 WebSharper.Main.min.js:1(未找到)”
bin\Debug文件夹中没有*.js文件。我运行的是VS 2019,带有.NET Framework 4.7.1
我遗漏了什么?我不知道这个示例是作为名为“WebSharper 4 Suave hosted Site”的模板提供的,这是我在下载并安装WebSharper vsix之后才发现的。该模板启动了一个项目,实现了我试图实现的目标。这就是答案。我希望在文档页面中有所暗示