#!/usr/bin/env elixir
defmodule Start do
defp mime_types() do
[
{'html', 'text/html'},
{'htm', 'text/html'},
{'js', 'text/javascript'},
{'css', 'text/css'},
{'gif', 'image/gif'},
{'jpg', 'image/jpeg'},
{'jpeg', 'image/jpeg'},
{'png', 'image/png'}
]
end
def start() do
abs_path = :string.trim(:filename.absname('output_folder'), :trailing, '/.')
:inets.start()
address = {127, 0, 0, 1}
ip_family_opts = []
{:ok, pid} =
:httpd.start_service(
bind_address: address,
document_root: abs_path,
server_root: abs_path,
directory_index: ['home'],
server_name: 'localhost',
port: 8008,
default_type: 'text/html',
mime_types: mime_types(),
modules:
[:mod_alias, :mod_dir, :mod_get] ++
ip_family_opts
)
receive do
{from, :shutdown} ->
:ok = :erlang.stop_service(pid)
send(from, :done)
end
end
end
Start.start()