0

I am developing a server with Ocaml/Dream. The server can be installed with Opam and called from anywhere in the disk. For the server icon, I use :

Dream.get  (favicon_path)
  (fun request ->
    Dream.from_filesystem "assets" "myiconfile.ico" request);

The problem with this code is that is works (the icon is displayed) only if I run my server from the root folder of my repository (I have indeed, asserts/myiconfile.ico in my repo).

I would like it to work even when the user launches the server from elsewhere by looking for the icon file in the "package" installed with opam.

It seems that Ocaml doesn't allow to "calculate" paths at compilation time but only at run time. Is that correct? and how to work it around? How do Dream developers typically do to use files embedded with their code (like in Java for instance)?

2
  • 1
    You need to install your icon in a directory and find them at runtime. The dune_site feature helps you by generating code that makes to retrieval of these files easier at runtime; you can even use --relocatable so that everything is inside the same directory. I never used it however, but here is the doc dune.readthedocs.io/en/stable/sites.html Commented Jul 31 at 9:02
  • Great! Works perfectly. Thanks @coredump. Commented Sep 12 at 9:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.