aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Coquand <marcc@fastmail.fr>2023-12-04 08:06:31 -0600
committerMarc Coquand <marcc@fastmail.fr>2023-12-04 08:06:31 -0600
commiteacb0f2e62b3a713083be9cc15b8af41fac2d6af (patch)
tree2255733cf314bd0d61467fffde8cea96dfbe0c90
parent47719821b568704739d42219076c2f7c02bf266b (diff)
downloadwormhole-eacb0f2e62b3a713083be9cc15b8af41fac2d6af.tar.gz
wormhole-eacb0f2e62b3a713083be9cc15b8af41fac2d6af.tar.bz2
wormhole-eacb0f2e62b3a713083be9cc15b8af41fac2d6af.zip
Add static assets in a single binary
-rw-r--r--assets/dune10
-rw-r--r--bin/main.ml7
-rw-r--r--dune-project1
-rw-r--r--wormhole.opam10
4 files changed, 19 insertions, 9 deletions
diff --git a/assets/dune b/assets/dune
new file mode 100644
index 0000000..0a984cb
--- /dev/null
+++ b/assets/dune
@@ -0,0 +1,10 @@
+(rule
+ (targets static.ml)
+ (deps (source_tree ./))
+ (action
+ (setenv OCAMLRUNPARAM "b"
+ (run %{bin:ocaml-crunch} --mode=plain -o static.ml -e css -e svg -e png -e jpg -e ttf ./))
+ ))
+
+(library (name assets)
+ (modules assets))
diff --git a/bin/main.ml b/bin/main.ml
index 49469a3..45bd973 100644
--- a/bin/main.ml
+++ b/bin/main.ml
@@ -67,6 +67,11 @@ let actor_allowlist =
"https://graphics.social/users/theohonohan";
]
+let loader _root path _request =
+ match Assets.read path with
+ | None -> Dream.empty `Not_Found
+ | Some asset -> Dream.respond asset
+
let () =
let port =
Sys.getenv_opt "PORT" |> Option.map int_of_string
@@ -84,7 +89,7 @@ let () =
Dream.run ~port ~interface @@ Dream.logger
@@ Dream.router
[
- Dream.get "/static/**" (Dream.static "./assets");
+ Dream.get "/static/**" (Dream.static ~loader "");
Dream.get "/feed.xml" (fun _ ->
let posts = Post.get_all () in
let maybe_latest_post = Post.latest_post () in
diff --git a/dune-project b/dune-project
index 35a8faf..deac556 100644
--- a/dune-project
+++ b/dune-project
@@ -1,6 +1,7 @@
(lang dune 3.11)
(name wormhole)
+(version 4771982-dirty)
(generate_opam_files true)
diff --git a/wormhole.opam b/wormhole.opam
index 46045e1..886447e 100644
--- a/wormhole.opam
+++ b/wormhole.opam
@@ -1,5 +1,7 @@
+version: "4771982-dirty"
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
+version: "4771982-dirty"
synopsis: "A short synopsis"
description: "A longer description"
maintainer: ["Maintainer Name"]
@@ -11,17 +13,9 @@ doc: "https://url/to/documentation"
bug-reports: "https://github.com/username/reponame/issues"
depends: [
"ocaml"
- "dream"
"dune" {>= "3.11"}
"ppx_yojson_conv"
- "cohttp"
- "cohttp-lwt-unix"
"odoc" {with-doc}
- "containers"
- "calendar"
- "ptime"
- "mirage-crypto-rng" {>= "0.11.0"}
- "mirage-crypto-rng-lwt" {>= "0.11.0"}
]
build: [
["dune" "subst"] {dev}