Easily run an http server from terminal
If available in Hex, this escript can be installed by running this command
mix escript.install hex elixir_serverOr directly from Github like this:
mix escript.install git https://github.com/vikram25897/elixir_serverYou can run it like this:
elixir_server --port 4000 --host any index.htmlor
elixir_server --p 4000 -h any index.htmlhost supports two values:
anyto bind on0.0.0.0loopbackto bind on127.0.0.1, defaults toloopback
port defaults to 4000
If no entrypoint file is provided, elixir_server searches for any of the following files in order:
index.htmlindex.exsindex.ex
Will fail if none of these 3 files are provided.
An elixir file path like index.ex or homepage.exs can be passed instead of html filepath.
When passing in an elixir file, make sure that:
- It contains exactly one module.
- That module either has public both
assigns/1andtemplate_path/1function or a singleraw_html/1function. assigns/1is expected to return a keyword list, like[name: "John Doe", age: 25]template_path/1is expected to return path of a template file. You can use EEx template syntax and assigns returned fromassigns/1function.raw_htmlexpects you to return a html string.
Instead of running an http server, you can instead generate an html file by passing --only_generate or -o flag like this:
elixir_server -o index.html output.htmlIf only one path is provided like this:
elixir_server -o output.htmlIt would be considered the output path and it would search for valid entrypoint as explained in Running Webserver section.