A site based of ocsigen-start fails to register/find a service after a straightforward change

I am playing with Ocsigen at the moment familiarising myself with the architecture and practices of using this web framework. A web-site is smoothly generated with ocsigen-start 2.16.1 in OCaml 4.10.0. Unfortunately, I got stuck with a very basic change I did on this fresh web-site, and at the moment I run out of ideas and knowledge.

ocsigen-start has so called “main_service” created in “os_services.eliom”, (actually, its compiled library installed by opam, but in this post I’ll be referring to the source code)

let%server main_service =
    ~path:(Eliom_service.Path [])
    ~meth:(Eliom_service.Get Eliom_parameter.unit)

and using the original names of template.distillery, registered in “PROJECT_NAME.eliom” that after the site generation is located in the fresh site’s folder, I creatively named my site “myapp” thus the file is called “myapp.eliom”

(Myapp_page.Opt.connected_page Myapp_handlers.main_service_handler);

According to my shake knowledge of Eliom, this service is responsible for the home page (e.g. localhost:8080/). I did not like the idea of having one of the pages generated by a pre-installed OCaml library, thus

  • I copied “Os_serivces.main_service” from “os_services.eliom” to “myapp_services.eliom”
  • with the related Myapp_services.eliomi" change and
  • replacing “Os_serivces.main_service” to “Myapp_serivces.main_service” in the rest of Myapp files
  • (basically, I searched for “main_service” and pedantically replaced all I could find). For example, “myapp_service.eliom” now contains

(Myapp_page.Opt.connected_page Myapp_handlers.main_service_handler);

Unfortunately, “make test.byte” command now returns the following error

ocsigenserver: ocsigen:main: Eliom: in site / - One service or coservice has not been registered on URL /.
ocsigenserver: ocsigen:main: Please correct your modules and make sure you have linked in all the modules…
make: *** [Makefile.os:87: test.byte] Error 20

the previously working site fails to runs, and after several attempts, I failed to understand why this is happening.

Do you have any ideas or better knowledge on how to make the site to behave?

Hello @dborisog,

All services created during initialization must be registered (with “site” scope) during the initialization phase of your module. If not, the server will not start, and an appropriate error message will appear in the logs. This prevents broken links.

Source: https://ocsigen.org/eliom/dev/manual/server-services#h5o-11

Os_services.main_service is such a service, so it needs to be registered.

In fact, what does ocsigen-start for you is just creating the main service but not its handler. Thus, you have total control over how to generate the main page by defining on your own the service handler of the main service.

I hope that helps.

Thank you for the tips, @ilankri.

At the moment, I stripped to the minimum code possible an another version of a website generated from ocsigen-start-based. For example, I renamed “main_service” and have it registered as an “Eliom_registration.Html.create” (non-app) service with a very basic handler, effectively having “mn_service” as the only service of the website. Unfortunately, the issue remains.

It pushed me to assume that some (dark?) magic is happening after running “make test.byte” command, thus just a few minutes ago opened the makefiles (e.g. Makefile.os that keeps test.byte command) and prepared for long hours of ocsigenserver documentation studies. For example, “local/var/www/site” contains plenty of “*.js” files, some of them reference to “main_service” of “Os_services”; I do not know whenhowwhy these files are generated; maybe “make test.byte” re-uses some of these obsolete files.

This exercise might be a complete time-burner as “ocsigen-start” is not a boilerplate script though it shares some of its characteristics.

Ocsigen Start’s library defines a few services (the main page or other very basic services). If you want to use Ocsigen Start, you must keep them (and register your own handler on them to gerenate the page).

@Vincent_Balat, Ocsigen-start imposes a “hardcoded” user model as a library, for this reason I no longer see Ocsigen-start as a foundation of an application unless the user model fully fits the project needs; Ocsigen-start is a rich source of practical knowledge.

Indeed. If you don’t want this, do not use Ocsigen Start as a basis for your project.
With Ocsigen Start we wanted to provide an app skeleton for this kind of app (as we implemented several apps with user management ourselves and we didn’t want to reimplement all this every time).
But Ocsigen Start remains a very good way to learn multi-tier programming

I suspect the issue might be related to Makefile scripts, but I cannot support pro- or contra-argumentation for this suspicion. I got a working example by gradually modifying Basic-based app with bits of code from Ospgocaml-based app and Ocsigen-services app/library.