首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >由于故障无法启动ocsigen服务器:(“该函数不能在这里调用,因为它需要有关请求或站点的信息”)。

由于故障无法启动ocsigen服务器:(“该函数不能在这里调用,因为它需要有关请求或站点的信息”)。
EN

Stack Overflow用户
提问于 2013-08-02 17:51:00
回答 1查看 136关注 0票数 2

我想要创建一个根据给定参数和地图生成HTML的服务。给定参数,服务在映射中搜索html,并在客户端启动一个函数。

代码语言:javascript
运行
复制
type sample =
  (string (* little text *)*
   Html5_types.html Eliom_content.Html5.elt (* html page *) *
  (unit -> unit)(* Demonstration function *))

考虑到函数将在客户端启动,我将它作为客户端值插入到映射中:

代码语言:javascript
运行
复制
{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

然后我像这样注册服务:

代码语言:javascript
运行
复制
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酿酒厂的结果,其中包含了用于客户端函数的ojquery包。编译阶段进行得很顺利,但是当我试图启动服务器时,我会得到以下错误消息:

ocsigenserver: main: Fatal - Error in configuration file: Error while parsing configuration file: Eliom: while loading local/lib/examples/examples.cma: Failure("That function cannot be called here because it needs information about the request or the site.")

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

我试图将它们包装成常规函数:let demo_serv_func () = {unit{demo_client_func ()}}

但问题依然存在..。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-05 15:20:20

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

碰巧,Eliom_tools需要服务的上下文才能起作用,而且由于我将它存储在服务之外,所以它无法工作。

通过在服务中使用Eliom_tools并将HTML页面的主体存储在地图中,我解决了这个问题。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18023145

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档