Created
August 19, 2014 03:32
-
-
Save yomimono/5533a8de0299dd599d97 to your computer and use it in GitHub Desktop.
config.ml for static site blog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Mirage | |
(* If the Unix `MODE` is set, the choice of configuration changes: | |
MODE=crunch (or nothing): use static filesystem via crunch | |
MODE=fat: use FAT and block device (run ./make-fat-images.sh) | |
*) | |
let mode = | |
try match String.lowercase (Unix.getenv "FS") with | |
| "fat" -> `Fat | |
| _ -> `Crunch | |
with Not_found -> | |
`Crunch | |
let fat_ro dir = | |
kv_ro_of_fs (fat_of_files ~dir ()) | |
let fs = match mode with | |
| `Fat -> fat_ro "../public" | |
| `Crunch -> crunch "../public" | |
let net = | |
try match Sys.getenv "NET" with | |
| "direct" -> `Direct | |
| "socket" -> `Socket | |
| _ -> `Direct | |
with Not_found -> `Direct | |
let dhcp = | |
try match Sys.getenv "DHCP" with | |
| "" -> false | |
| _ -> true | |
with Not_found -> true | |
(* if dhcp == false, ipaddr defined, netmask defined, at least one gateway defined, | |
* figure out an ipv4 object to pass to direct_stackv4_with_static_ipv4 *) | |
let stack console = | |
match net, dhcp with | |
| `Direct, true -> direct_stackv4_with_dhcp console tap0 | |
| `Direct, false -> direct_stackv4_with_default_ipv4 console tap0 | |
| `Socket, _ -> socket_stackv4 console [Ipaddr.V4.any] | |
let server = | |
http_server 80 (stack default_console) | |
let main = | |
foreign "Dispatch.Main" (console @-> kv_ro @-> http @-> job) | |
let () = | |
add_to_opam_packages["re"]; | |
add_to_ocamlfind_libraries["re.str"]; | |
register "www" [ | |
main $ default_console $ fs $ server | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment