58 lines
2.1 KiB
OCaml
58 lines
2.1 KiB
OCaml
(* 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
|
|
the Free Software Foundation, version 3.
|
|
|
|
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/>. *)
|
|
|
|
let hello req _server _env =
|
|
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
|
|
|
|
let routes =
|
|
let open Vif.Uri in
|
|
let open Vif.Route in
|
|
let open Vif.Type in
|
|
(* just for alignement *)
|
|
let get_ = get in
|
|
let post = Fun.flip post in
|
|
[
|
|
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;
|
|
]
|
|
|
|
let () =
|
|
Util.Log_reporter.setup ();
|
|
let cfg =
|
|
let port = Config.Exchange.port in
|
|
let sockaddr = Unix.(ADDR_INET (inet_addr_loopback, port)) in
|
|
Vif.config ~reporter:Util.Log_reporter.reporter sockaddr
|
|
in
|
|
Miou_unix.run @@ fun () ->
|
|
Caqti_miou.Switch.run @@ fun caqti_switch ->
|
|
let env : Devices.env =
|
|
{ caqti_switch; db_uri= Config.Exchangedb_postgres.config }
|
|
in
|
|
let devices =
|
|
Vif.Devices.
|
|
[ Devices.db_connection; Devices.secmod_signkey; Devices.secmod_denom ]
|
|
in
|
|
let middlewares = Vif.Middlewares.[] in
|
|
Logs.info (fun m ->
|
|
m ~tags:(Util.Log_reporter.detail "...") "Starting MTE server");
|
|
Vif.run ~cfg ~devices ~middlewares routes env
|