diff --git a/examples/dune b/examples/dune index 83b0aa84..00ab1a10 100644 --- a/examples/dune +++ b/examples/dune @@ -12,7 +12,7 @@ (executable (name echo) (flags :standard -warn-error -a+8) - (modules echo) + (modules echo vfs) (libraries tiny_httpd tiny_httpd_camlzip)) (rule @@ -30,3 +30,13 @@ (deps test_output.txt) (action (diff test_output.txt.expected test_output.txt))) + +; produce an embedded FS +(rule + (targets vfs.ml) + (deps (source_tree files) (:out test_output.txt.expected)) + (enabled_if (= %{system} "linux")) + (action (run ../src/bin/vfs_pack.exe -o %{targets} + --mirror=files/ + --file=test_out.txt,%{out} + --url=example_dot_com,http://example.com))) diff --git a/examples/echo.ml b/examples/echo.ml index f77bbe72..d2ae7b16 100644 --- a/examples/echo.ml +++ b/examples/echo.ml @@ -107,16 +107,23 @@ let () = S.Response.make_string @@ Ok stats ); + (* VFS *) + Tiny_httpd_dir.add_vfs server + ~config:(Tiny_httpd_dir.config ~download:true + ~dir_behavior:Tiny_httpd_dir.Index_or_lists ()) + ~vfs:Vfs.vfs ~prefix:"vfs"; + (* main page *) S.add_route_handler server S.Route.(return) (fun _req -> let s = "\n\

welcome!\n

endpoints are:\n

" in S.Response.make_string ~headers:["content-type", "text/html"] @@ Ok s); diff --git a/examples/files/a.txt b/examples/files/a.txt new file mode 100644 index 00000000..94954abd --- /dev/null +++ b/examples/files/a.txt @@ -0,0 +1,2 @@ +hello +world diff --git a/examples/files/foo.html b/examples/files/foo.html new file mode 100644 index 00000000..2f00ada8 --- /dev/null +++ b/examples/files/foo.html @@ -0,0 +1,18 @@ + + + + + + +

hello!

+ + + escape from this file + + + diff --git a/examples/files/sub/b.txt b/examples/files/sub/b.txt new file mode 100644 index 00000000..8493a14a --- /dev/null +++ b/examples/files/sub/b.txt @@ -0,0 +1 @@ +lorem ipsum etc. diff --git a/examples/files/sub/yolo.html b/examples/files/sub/yolo.html new file mode 100644 index 00000000..c7ecbf5e --- /dev/null +++ b/examples/files/sub/yolo.html @@ -0,0 +1,18 @@ + + + + + + +

funky:

+ + + +