Update for Elixir (1.17.1):
elixir --no-halt -e 'Application.start(:inets); :inets.start(:httpd, port: 8000, server_root: ~c".", document_root: ~c"./doc", server_name: ~c"localhost", mime_types: [{~c"html",~c"text/html"},{~c"htm",~c"text/html"},{~c"js",~c"text/javascript"},{~c"css",~c"text/css"},{~c"gif",~c"image/gif"},{~c"jpg",~c"image/jpeg"},{~c"jpeg",~c"image/jpeg"},{~c"png",~c"image/png"}])'
This example uses the doc
directory for a quick way to locally host/view docs generated with ExDoc
.
Here's the more readable version of the string being eval'd, shown as an iex
session:
iex(1)> Application.start(:inets)
:ok
iex(2)> :inets.start(:httpd,
...(2)> port: 8000,
...(2)> server_root: ~c".",
...(2)> document_root: ~c"./doc",
...(2)> server_name: ~c"localhost",
...(2)> mime_types: [
...(2)> {~c"html", ~c"text/html"},
...(2)> {~c"htm", ~c"text/html"},
...(2)> {~c"js", ~c"text/javascript"},
...(2)> {~c"css", ~c"text/css"},
...(2)> {~c"gif", ~c"image/gif"},
...(2)> {~c"jpg", ~c"image/jpeg"},
...(2)> {~c"jpeg", ~c"image/jpeg"},
...(2)> {~c"png", ~c"image/png"}
...(2)> ]
...(2)> )
{:ok, #PID<0.118.0>}
^ woops- just found this
It's not technically a one-liner, but my use-case is better solved with:
mix do hex.docs fetch + docs && cp -r doc "${HEX_HOME}/docs/hexpm/${OTP_APP}/${OTP_APP_VERSION}" && mix hex.docs offline "${OTP_APP}"