htmlhaskelluser-interfacelocalhostthreepenny-gui

threepenny-gui - opening files


Dear Haskell community I have written my first gui application and decided to use threepenny-gui to do so.

The task is the following search the files in a given folder for matches and provide links to open those files. In addition I made nice parse and render function as the files (mostly) have a special formatting.

But now I have stumbled upon a problem - most browsers prohibit links to local files by href="file://localhost/home/user/folder/file.pdf" being opened, for security reasons, which I do understand and find completely sensible.

I tried to use href="./file.pdf" when the program and the file are in the same folder, which also doesn't seem to work.

The code of the whole application is available at github/epsilonhalbe, I run it in a folder and access it via a browser at localhost:100000


Solution

  • The HTTP server provided by threepenny-gui will serve up static content from the directory you specify in tpStatic. Put your files in that directory, and make your links' paths be relative to it, and you'll be good to go!

    As of threepenny-gui-0.4.*, there are also two functions loadFile and loadDirectory that can be used to serve a local file or directory at an automatically generated URL. This can be useful if the tpStatic field is not enough.