mte/src/mte.ml

59 lines
2.1 KiB
OCaml
Raw Normal View History

2025-09-21 17:44:14 +02:00
(* MTE - the MirageOS Taler Exchange
Copyright (C) 2025 Olivier Pierre <swrup@protonmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
2025-09-28 16:58:47 +02:00
the Free Software Foundation, version 3.
2025-09-21 17:44:14 +02:00
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. *)
2025-09-28 20:04:52 +02:00
let hello req _server _env =
2025-09-28 22:12:16 +02:00
let open Vif.Response in
let open Syntax in
let* () = with_string req "Hello~~\n" in
let* () = add ~field:"content-type" "text/plain" in
respond `OK
2025-09-28 20:04:52 +02:00
2025-09-13 15:56:19 +02:00
let routes =
let open Vif.Uri in
let open Vif.Route in
2025-11-28 19:17:25 +01:00
let open Vif.Type in
2025-11-29 19:36:35 +01:00
(* just for alignement *)
let get_ = get in
let post = Fun.flip post in
2025-09-13 15:56:19 +02:00
[
2025-11-29 19:36:35 +01:00
get_ (rel /?? nil) --> hello;
get_ (rel / "terms" /?? nil) --> Static.terms;
get_ (rel / "privacy" /?? nil) --> Static.privacy;
get_ (rel / "test" /?? nil) --> Database.test_activate;
get_ (rel / "management" / "keys" /?? nil) --> Management.keys_get;
post (rel / "management" / "keys" /?? nil) any --> Management.keys_post;
2025-09-13 15:56:19 +02:00
]
2025-09-13 17:57:29 +02:00
let () =
2025-11-29 19:36:35 +01:00
Util.Log_reporter.setup ();
2025-09-28 20:52:25 +02:00
let cfg =
2025-10-13 11:48:29 +02:00
let port = Config.Exchange.port in
2025-09-28 20:52:25 +02:00
let sockaddr = Unix.(ADDR_INET (inet_addr_loopback, port)) in
2025-11-29 19:36:35 +01:00
Vif.config ~reporter:Util.Log_reporter.reporter sockaddr
2025-09-28 20:52:25 +02:00
in
2025-09-13 17:57:29 +02:00
Miou_unix.run @@ fun () ->
2025-11-11 03:12:12 +01:00
Caqti_miou.Switch.run @@ fun caqti_switch ->
let env : Devices.env =
{ caqti_switch; db_uri= Config.Exchangedb_postgres.config }
in
let devices =
2025-11-22 21:40:24 +01:00
Vif.Devices.
2025-11-28 07:47:51 +01:00
[ Devices.db_connection; Devices.secmod_signkey; Devices.secmod_denom ]
2025-11-11 03:12:12 +01:00
in
2025-09-13 17:57:29 +02:00
let middlewares = Vif.Middlewares.[] in
2025-11-29 19:36:35 +01:00
Logs.info (fun m ->
m ~tags:(Util.Log_reporter.detail "...") "Starting MTE server");
2025-10-18 18:19:09 +02:00
Vif.run ~cfg ~devices ~middlewares routes env