Exhtml is a library that handles HTML page serving. There are some benifts to have a dynamic HTML page host rather than static server:
- it's easy to deploy a small number of pages.
- it's safer to make the HTML server pull content from backend storage than push contents to it.
- you can add middlewares as you wish, such as performance monitoring, server-side procsessing, etc..
If available in Hex, the package can be installed as:
- Add
exhtml
to your list of dependencies inmix.exs
:
def deps do
[{:exhtml, "~> 0.1.0"}]
end
- Ensure
exhtml
is started before your application:
def application do
[applications: [:exhtml]]
end
- (optional) Add configuration into your project:
use Mix.Config
# `content_fetcher` can either be a module or a function
# `MyContentFetcher.fetch` accepts a key and returns content for the key.
config :exhtml,
# use a function in named module as a fetcher:
# content_fetcher: &MyContentFetcher.fetch/1,
# or use an anonymous function:
content_fetcher: fn slug -> "#{slug} content on remote" end,
# where to store contents on disk:
data_dir: "/home/data/exhtml_contents"
# update content.
# Notice: contents live in memory and automaticly persisted in disk.
Exhtml.update_content :my_page
# later, get content:
Exhtml.get_content :my_page
#=> "my_page content on remote"
MIT liccense
- Pull requests are welcome.
- Issues here