Closed shonfeder closed 2 months ago
I've got a workaround that may be useful to report:
The problem I hit is this: while it is obvious how to register an initialization function, it is not at all obvious (to me) how to get that registered init function to be called.
From digging in to ocsigen a git, it seems like the only time these init functions get called is during the parsing of a configuration file (https://github.com/ocsigen/ocsigenserver/blob/7950e0a462164398a4b6af780d2981b0ab7b2149/src/server/ocsigen_parseconfig.ml#L379-L380). Since I am trying to port an existing site (that used opium), and have been trying to use the (iiuc) newer "static" API via Ocsigen_server.start
I don't have any such config file to parse. As such, my init function is never getting called.
Based on the docs, I tried to add various XML values to a config file, hoping to get the init function triggered, using ~configfile
label to tell start
where to find it, but the file was either ignored of failed silently.
Ultimately, this hack fixed the problem for me: https://github.com/shonfeder/ocsigenserver/commit/75c300b11b990f4d594c7e483dc12c3245b60e94
Of course, I lose the nifty dynamic reloading functionality, but this is not worse off than I was before.
It would be very nice to expose the dynamic reloading functionality via the Ocsigen_server.start
API, without having to add an XML file just for this purpose. However, I also think an API to just tell start
which services it needs to register, or which init function it needs to all, would be a user-friendly way to make using the static API easier.
As an example, it would be convenient to be able to call something like:
Ocsigen_server.start
~ports:([`All, port])
~init:(my_init_function:unit -> unit)
[ Ocsigen_server.host ~port
[ Eliom.run () ]]
Tho I can imagine some APIs that may be even cleaner (e.g., just taking a list of services and registering them).
Hello Shon, This error message usually happens when a function is called during the initialisation phase of the server (before the server starts) while it should be during a request. It means that this function needs to know the exact configuration (path usually) for a service or a scoped reference. This happens for example if you try to get some session values (Eliom references) outside a function. The easy fix is to turn your value into a function which is called during page generation. In your case it seems to be getting some information about the request (which can be done obviously only during a request). Maybe a reference with scope `Request in a form?
You shouldn't need to call register_eliom_module
yourself. This is an internal function.
Does it help to solve your issue? Don't hesitate to ask more questions. I will try to check more frequently.
Our next huge documentation improvement is going to be about make the API documentation simpler to read, but working on tools and separating low level functions from the function you actually need for every day use. But this takes time.
Hello! It looks like I may have gotten a bit confused somewhere between my own migration to Ocsigen and my (misreading) of the docs on static liking eliom modules :sweat_smile:
Your clarification here, and my own further investigations, have cleared the way. I have turned some fragments of html in thunks, made some targeted use of lazy values to avoid needless recomputations.
Thank you for the guidance, and I'm sorry for the noise here!
You're welcome. This error is vey frequent anyway. I will find a way to document it better.
I am trying to complete the migration of a simple site to Ocsigen and Eliom. I've nearly completed the migration, but I think I am now running up against the complexity of static liking eliom modules. E.g., trying to run the server defined using
Ocsigen_server.start
, I hitI believe I am hitting the problem discussed in https://ocsigen.org/eliom/latest/api/server/Eliom_service#2_StaticloadingofEliommodules . I expect I can eventually figure out how to work around this by trial and error, or studying the implementation, but it would be very helpful if there were an example of how to work around this kind of problem.