mirror of
https://github.com/mgerb/classic-wow-forums
synced 2026-01-11 17:42:48 +00:00
prepare router to serve single page web app
This commit is contained in:
22
lib/myapp_web/controllers/page_controller.ex
Normal file
22
lib/myapp_web/controllers/page_controller.ex
Normal file
@@ -0,0 +1,22 @@
|
||||
defmodule MyAppWeb.PageController do
|
||||
use MyAppWeb, :controller
|
||||
|
||||
# serve index.html - cache the file after reading it to minimize IO
|
||||
@spec index(map, map) :: any
|
||||
def index(conn, _params) do
|
||||
|
||||
file = Cachex.get(:myapp, "index.html")
|
||||
|> get_file
|
||||
|
||||
conn
|
||||
|> html(file)
|
||||
end
|
||||
|
||||
defp get_file({:ok, data}), do: data
|
||||
defp get_file({:missing, _}) do
|
||||
file = File.read!("./priv/static/index.html")
|
||||
Cachex.set(:myapp, "index.html", file)
|
||||
file
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user