-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathdocs.exs
More file actions
33 lines (24 loc) · 689 Bytes
/
docs.exs
File metadata and controls
33 lines (24 loc) · 689 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Mix.install([
{:bandit, "~> 1.1"}
])
defmodule Router do
@moduledoc false
use Plug.Router
def port, do: 8000
def origin, do: "http://localhost:#{port()}"
plug(Plug.Logger)
plug(:match)
plug(:dispatch)
plug Plug.Static, at: "/docs", from: "doc", gzip: false
match _ do
conn
|> Plug.Conn.resp(:found, "")
|> Plug.Conn.put_resp_header("location", "#{origin()}/docs/readme.html")
end
end
bandit = {Bandit, plug: Router, scheme: :http, port: Router.port()}
{:ok, _} = Supervisor.start_link([bandit], strategy: :one_for_one)
# unless running from IEx, sleep idenfinitely so we can serve requests
unless IEx.started?() do
Process.sleep(:infinity)
end