4

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

duplode
  • 33,731
  • 7
  • 79
  • 150
epsilonhalbe
  • 15,637
  • 5
  • 46
  • 74
  • I can't get the "Scan" button to do anything. You should include some instructions for reproducing a problem. But presumably the correct answer is to make all paths relative to the path you put in `tpStatic` in `main`. And I'm sure you won't be able to go outside of that directory (e.g. to `../something`). – Daniel Wagner Jan 26 '14 at 21:54
  • Oh thank you a very lot Daniel Wagner - please write your comment as an answer so I can accept it! I just had to put the files in the static directory. - The reason why the scan button is not working I guess is that there are no pdf files that it can find. – epsilonhalbe Jan 26 '14 at 22:40

1 Answers1

5

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.

Heinrich Apfelmus
  • 11,034
  • 1
  • 39
  • 67
Daniel Wagner
  • 145,880
  • 9
  • 220
  • 380