Replace config url type from String.t to Uri.t
This commit is contained in:
parent
aac1a65e4c
commit
43a52f549b
@ -8,4 +8,4 @@
|
|||||||
(executable
|
(executable
|
||||||
((name logarion_webserver)
|
((name logarion_webserver)
|
||||||
(modules logarion_webserver)
|
(modules logarion_webserver)
|
||||||
(libraries (logarion logarion.converters lwt.unix opium.unix re.str tyxml))))
|
(libraries (logarion logarion.converters lwt.unix opium.unix uri re.str tyxml))))
|
@ -5,16 +5,14 @@ module Template = Converters.Template
|
|||||||
|
|
||||||
module Configuration = struct
|
module Configuration = struct
|
||||||
type t = {
|
type t = {
|
||||||
url : string;
|
url : Uri.t;
|
||||||
port : int;
|
|
||||||
static : Fpath.t;
|
static : Fpath.t;
|
||||||
styles : Fpath.t list;
|
styles : Fpath.t list;
|
||||||
template : Template.Configuration.paths_t;
|
template : Template.Configuration.paths_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
let default = {
|
let default = {
|
||||||
url = "";
|
url = Uri.empty;
|
||||||
port = 3666;
|
|
||||||
static = Fpath.v "/usr/share/logarion/static";
|
static = Fpath.v "/usr/share/logarion/static";
|
||||||
styles = [];
|
styles = [];
|
||||||
template = Template.Configuration.default_paths;
|
template = Template.Configuration.default_paths;
|
||||||
@ -25,10 +23,10 @@ module Configuration = struct
|
|||||||
match result with
|
match result with
|
||||||
| `Error (str, loc) -> default
|
| `Error (str, loc) -> default
|
||||||
| `Ok toml ->
|
| `Ok toml ->
|
||||||
|
let default_url = Uri.to_string default.url in
|
||||||
let open Logarion.Config in
|
let open Logarion.Config in
|
||||||
{
|
{
|
||||||
url = str toml "general" "url" default.url;
|
url = str toml "general" "url" default_url |> Uri.of_string;
|
||||||
port = int toml "general" "port" default.port;
|
|
||||||
static = path toml "general" "static_dir" default.static;
|
static = path toml "general" "static_dir" default.static;
|
||||||
styles = paths toml "general" "stylesheets" default.styles;
|
styles = paths toml "general" "stylesheets" default.styles;
|
||||||
template = Template.Configuration.of_toml_file toml
|
template = Template.Configuration.of_toml_file toml
|
||||||
@ -71,7 +69,7 @@ let () =
|
|||||||
let item_tpl = Template.item wcfg.Configuration.template in
|
let item_tpl = Template.item wcfg.Configuration.template in
|
||||||
let note_tpl = Template.note wcfg.Configuration.template in
|
let note_tpl = Template.note wcfg.Configuration.template in
|
||||||
|
|
||||||
let blog_url = Configuration.(wcfg.url) in
|
let blog_url = Uri.to_string wcfg.Configuration.url in
|
||||||
let module Html = Converters.Html in
|
let module Html = Converters.Html in
|
||||||
let page_of_msg = Html.of_message ~header_tpl blog_url config in
|
let page_of_msg = Html.of_message ~header_tpl blog_url config in
|
||||||
let page_of_note = Html.of_note ~header_tpl ~note_tpl blog_url config in
|
let page_of_note = Html.of_note ~header_tpl ~note_tpl blog_url config in
|
||||||
@ -83,7 +81,7 @@ let () =
|
|||||||
let (>>=) = Lwt.(>>=) and (>|=) = Lwt.(>|=) in
|
let (>>=) = Lwt.(>>=) and (>|=) = Lwt.(>|=) in
|
||||||
let atom_response repo req =
|
let atom_response repo req =
|
||||||
Lwt.return (L.latest_listed repo)
|
Lwt.return (L.latest_listed repo)
|
||||||
>|= Converters.Atom.feed config wcfg.Configuration.url (L.note_with_id lgrn)
|
>|= Converters.Atom.feed config blog_url (L.note_with_id lgrn)
|
||||||
>>= html_response
|
>>= html_response
|
||||||
in
|
in
|
||||||
let post_note lgrn req =
|
let post_note lgrn req =
|
||||||
@ -117,7 +115,7 @@ let () =
|
|||||||
in
|
in
|
||||||
|
|
||||||
App.empty
|
App.empty
|
||||||
|> App.port wcfg.Configuration.port
|
|> App.port (match Uri.port wcfg.Configuration.url with Some p -> p | None -> 3666)
|
||||||
|> middleware @@
|
|> middleware @@
|
||||||
Middleware.static
|
Middleware.static
|
||||||
~local_path:(Fpath.to_string wcfg.Configuration.static)
|
~local_path:(Fpath.to_string wcfg.Configuration.static)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user