package cohttp_static_handler

  1. Overview
  2. Docs
type t

Represents a single page handler's generated index page.

val default : t

A handler created using default serves a boilerplate index page.

val default_with_body_div : div_id:string -> t

A handler created using default_with_body_div ~div_id serves a boilerplate index page that has a div within the body tag with the given div_id.

val create : body:string -> t

A handler created using create body serves a page where body is wrapped in an html tag alongside a head tag. Users must provide the actual body tags themselves.

val create_handler : ?log:Async.Log.t -> ?title:string -> t -> assets:Asset.t list -> on_unknown_url:[ `Not_found | `Index ] -> Http_handler.t

create_handler ?log ?title t ~assets ~on_unknown_url returns a handler that serves the provided assets, along with an index page based on t that loads the assets.

assets will be included in the page via link or script declarations as appropriate for the type of asset.

Depending on on_unknown_url, it will satisfy requests for unrecognized paths with:

  • `Not_found: a 404 error page
  • `Index: the index page

This is useful for incr_dom/single-page javascript applications; ~on_unknown_url:`Index is important for applications that intend to do client-side routing.

Requests are logged to log, which defaults to Log.Global.log.

Setting title changes the page title displayed in the browser's title bar.

OCaml

Innovation. Community. Security.