ocaml - 由于故障 : ("That function cannot be called here because it needs information about the request or the site."),无法启动 ocsigen 服务器

标签 ocaml ocsigen

我想创建一个根据给定参数和 map 生成 HTML 的服务。给定参数,服务在 map 中搜索 html,以及在客户端启动的函数。

type sample =
  (string (* little text *)*
   Html5_types.html Eliom_content.Html5.elt (* html page *) *
  (unit -> unit)(* Demonstration function *))

鉴于该功能要在客户端启动,我将其作为客户端值插入到 map 中:

{client{
 let demo_function = ignore (Ojquery.add_html 
                             (Ojquery.jQ "li") "<p id='test1'>new paragraph</p>") }}

let get_samples () =
  let samples_map = Samples.empty in
  let samples_map = Samples.add "add_html"
    ("text",
     (Eliom_tools.F.html
       (** html stuff **)
      ),
   {unit->unit{demo_function}}) samples_map in
  samples_map

然后我像这样注册服务:

let sample_service =
  Eliom_service.service
    ~path:["examples"]
    ~get_params:Eliom_parameter.(string "entry")
  ()
let () =
  Examples_app.register
    ~service:sample_service
    (fun (entry) () ->
      try
        (let entry = Samples.find entry samples_map in
        let html = ((function (name, html, func) -> html) entry) in
        let func = ((function (name, html, func) -> func) entry) in
        ignore {unit{%func ()}};
        Lwt.return (html))
    with Not_found -> Lwt.return (not_found)
  )

其余的代码几乎只是经典 eliom-distillery 的结果,其中包含所使用的客户端函数的 ojquery 包。 编译阶段进行得很顺利,但是当我尝试启动服务器时,我收到以下错误消息:

ocsigenserver:主要:致命 - 配置文件中的错误:解析配置文件时出错:Eliom:加载 local/lib/examples/examples.cma 时:失败(“无法在此处调用该函数,因为它需要信息”关于请求或网站。")

我的第一个猜测是,这是因为我将客户端值存储在服务之外,但是有什么方法可以将这种值存储在服务器上吗?

我尝试将它们包装在常规函数中: 让 demo_serv_func () = {unit{demo_client_func ()}}

但问题仍然存在......

最佳答案

我发现了这个问题。问题不是因为我存储了客户端函数,而是因为我在服务之外使用了 Eliom_tools.F.html

Eliom_tools 恰好需要服务的上下文才能运行,并且由于我将其存储在服务之外,因此它无法工作。

我通过在服务内使用 Eliom_tools 并将 HTML 页面的正文存储在 map 中解决了该问题。

关于ocaml - 由于故障 : ("That function cannot be called here because it needs information about the request or the site."),无法启动 ocsigen 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18023145/

相关文章:

企业堆栈中的 OCaml

ocaml - 在 Ocaml 中展平列表的代码错误

ocaml - 编译 ocaml-websocket 失败

ocaml - 使用 Ocsigen 提供 JSON 的规范方法是什么?

ocaml - ocsigenserver : You are not allowed to use port 80

ocaml - 如何使某些东西支持 lwt?

algorithm - 在 OCaml 的所有三个列表中找到至少一个存在的元素

ocaml - 2 个具有相同(文件)名称的 ocaml 模块

ocaml - 如何让 ocamlopt 链接到 glibc 2.5?