commit ed29333a87d28bb2f4329a1a74a136ef7371d918 Author: Nathan Anderson Date: Sun Aug 13 22:44:10 2023 -0600 WIP server diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c6a151b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +_build/ \ No newline at end of file diff --git a/.ignore b/.ignore new file mode 100644 index 0000000..69fa449 --- /dev/null +++ b/.ignore @@ -0,0 +1 @@ +_build/ diff --git a/.ocamlformat b/.ocamlformat new file mode 100644 index 0000000..e69de29 diff --git a/bin/dune b/bin/dune new file mode 100644 index 0000000..82427cb --- /dev/null +++ b/bin/dune @@ -0,0 +1,4 @@ +(executable + (public_name oasis_server) + (name main) + (libraries oasis_server dream core)) diff --git a/bin/main.ml b/bin/main.ml new file mode 100644 index 0000000..0e1ada7 --- /dev/null +++ b/bin/main.ml @@ -0,0 +1,13 @@ +let () = + print_endline "Hello, World!"; + Dream.run @@ Dream.logger + @@ Dream.router + [ + Dream.get "/static/**" @@ Dream.static "static"; + Oasis_server.Utils.html_page_route "/"; + Dream.get "/echo/:message" (fun request -> + Dream.html (Dream.param request "message")); + Dream.get "/test" (fun _ -> + Unix.sleep 1; + Dream.html "

You got me!

"); + ] diff --git a/data.db b/data.db new file mode 100644 index 0000000..ecc4944 Binary files /dev/null and b/data.db differ diff --git a/dune-project b/dune-project new file mode 100644 index 0000000..e19f7d2 --- /dev/null +++ b/dune-project @@ -0,0 +1,26 @@ +(lang dune 3.10) + +(name oasis_server) + +(generate_opam_files true) + +(source + (github username/reponame)) + +(authors "Author Name") + +(maintainers "Maintainer Name") + +(license LICENSE) + +(documentation https://url/to/documentation) + +(package + (name oasis_server) + (synopsis "A short synopsis") + (description "A longer description") + (depends ocaml core dune dream lwt lwt_ppx caqti caqti-lwt caqti-driver-sqlite3) + (tags + (topics "to describe" your project))) + +; See the complete stanza docs at https://dune.readthedocs.io/en/stable/dune-files.html#dune-project diff --git a/html/index.html b/html/index.html new file mode 100644 index 0000000..0ff0543 --- /dev/null +++ b/html/index.html @@ -0,0 +1,39 @@ + + + + + Peimono + + + + + + + + +

Hello there!!

+ + +
+ + + \ No newline at end of file diff --git a/html/page_template.html b/html/page_template.html new file mode 100644 index 0000000..1f2f056 --- /dev/null +++ b/html/page_template.html @@ -0,0 +1,17 @@ + + + + + Page Title + + + + + + + +

Hello there!!

+ + + \ No newline at end of file diff --git a/lib/db.ml b/lib/db.ml new file mode 100644 index 0000000..f1c65b0 --- /dev/null +++ b/lib/db.ml @@ -0,0 +1,31 @@ +type user = { id : int; name : string } + +let conn_str = "sqlite3:./data.db" + +module type DB = Caqti_lwt.CONNECTION + +let get_all_users_q = Caqti_request.Infix() + +let pool = + let uri = Uri.of_string conn_str in + match Caqti_lwt.connect_pool ~max_size:10 uri with + | Ok pool -> pool + | Error err -> failwith (Caqti_error.show err) + +let get_users = + let get_users' (module C: Caqti_lwt.CONNECTION) = + C.fold get_all_users_q + + let find_users = + let open Lwt_result.Infix in + fun (module Db : Caqti_lwt.CONNECTION) -> + Db.collect_list find_users_request () >>| List.map make_user + + let () = + let uri = Uri.of_string conn_str in + match Lwt_main.run (Caqti_lwt.connect uri >>= find_users) with + | Ok users -> + List.iter (fun user -> Printf.printf "%d: %s\n" user.id user.name) users + | Error err -> + Format.eprintf "%a@." Caqti_error.pp err + diff --git a/lib/dune b/lib/dune new file mode 100644 index 0000000..d6d9ced --- /dev/null +++ b/lib/dune @@ -0,0 +1,3 @@ +(library + (name oasis_server) + (libraries dream lwt_ppx caqti-lwt caqti-driver-sqlite3)) diff --git a/lib/math.ml b/lib/math.ml new file mode 100644 index 0000000..eda1b9c --- /dev/null +++ b/lib/math.ml @@ -0,0 +1,2 @@ +let add x y = x + y +let sub x y = x - y diff --git a/lib/utils.ml b/lib/utils.ml new file mode 100644 index 0000000..973ef0b --- /dev/null +++ b/lib/utils.ml @@ -0,0 +1,5 @@ +let html_page_route path = + let ic = open_in ("html" ^ path ^ "index.html") in + let lines = In_channel.input_all ic in + In_channel.close ic; + Dream.get path (fun _ -> Dream.html lines) diff --git a/oasis_server.opam b/oasis_server.opam new file mode 100644 index 0000000..ab6d79b --- /dev/null +++ b/oasis_server.opam @@ -0,0 +1,38 @@ +# This file is generated by dune, edit dune-project instead +opam-version: "2.0" +synopsis: "A short synopsis" +description: "A longer description" +maintainer: ["Maintainer Name"] +authors: ["Author Name"] +license: "LICENSE" +tags: ["topics" "to describe" "your" "project"] +homepage: "https://github.com/username/reponame" +doc: "https://url/to/documentation" +bug-reports: "https://github.com/username/reponame/issues" +depends: [ + "ocaml" + "core" + "dune" {>= "3.10"} + "dream" + "lwt" + "lwt_ppx" + "caqti" + "caqti-lwt" + "caqti-driver-sqlite3" + "odoc" {with-doc} +] +build: [ + ["dune" "subst"] {dev} + [ + "dune" + "build" + "-p" + name + "-j" + jobs + "@install" + "@runtest" {with-test} + "@doc" {with-doc} + ] +] +dev-repo: "git+https://github.com/username/reponame.git" diff --git a/static/tail-spin.svg b/static/tail-spin.svg new file mode 100644 index 0000000..075a399 --- /dev/null +++ b/static/tail-spin.svg @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/test/dune b/test/dune new file mode 100644 index 0000000..5d743c1 --- /dev/null +++ b/test/dune @@ -0,0 +1,2 @@ +(test + (name oasis_server)) diff --git a/test/oasis_server.ml b/test/oasis_server.ml new file mode 100644 index 0000000..e69de29