forked from elixir-tools/tableau
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.ex
46 lines (33 loc) · 936 Bytes
/
router.ex
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
34
35
36
37
38
39
40
41
42
43
44
45
46
defmodule Tableau.Router do
@moduledoc false
use Plug.Router, init_mode: :runtime
import Tableau.Strung
require Logger
@base_path Path.join("/", Application.compile_env(:tableau, :config)[:base_path] || "")
@not_found ~g'''
<!DOCTYPE html><html lang="en"><head></head><body>Not Found</body></html>
'''html
plug :recompile
plug :rerender
plug Tableau.IndexHtml
plug Plug.Static, at: @base_path, from: "_site", cache_control_for_etags: "no-cache"
plug :match
plug :dispatch
get "/ws/index.html" do
conn
|> WebSockAdapter.upgrade(Tableau.Websocket, [], timeout: 60_000)
|> halt()
end
match _ do
Logger.error("File not found: #{conn.request_path}")
send_resp(conn, 404, @not_found)
end
defp recompile(conn, _) do
WebDevUtils.CodeReloader.reload()
conn
end
defp rerender(conn, _) do
Mix.Task.rerun("tableau.build", ["--out", "_site"])
conn
end
end