mirror of
https://github.com/mgerb/classic-wow-forums
synced 2026-01-09 16:42:49 +00:00
prepare router to serve single page web app
This commit is contained in:
@@ -14,6 +14,9 @@ defmodule MyApp.Application do
|
||||
supervisor(MyAppWeb.Endpoint, []),
|
||||
# Start your own worker by calling: MyApp.Worker.start_link(arg1, arg2, arg3)
|
||||
# worker(MyApp.Worker, [arg1, arg2, arg3]),
|
||||
|
||||
# start cachex for key/value store
|
||||
worker(Cachex, [:myapp, []])
|
||||
]
|
||||
|
||||
# See https://hexdocs.pm/elixir/Supervisor.html
|
||||
|
||||
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
|
||||
@@ -8,8 +8,9 @@ defmodule MyAppWeb.Endpoint do
|
||||
# You should set gzip to true if you are running phoenix.digest
|
||||
# when deploying your static files in production.
|
||||
plug Plug.Static,
|
||||
at: "/", from: :myapp, gzip: false,
|
||||
only: ~w(css fonts images js favicon.ico robots.txt)
|
||||
at: "/", from: :myapp, gzip: true
|
||||
# serve everything in the static folder
|
||||
# only: ~w(css *.css fonts images js favicon.ico robots.txt)
|
||||
|
||||
# Code reloading can be explicitly enabled under the
|
||||
# :code_reloader configuration of your endpoint.
|
||||
|
||||
@@ -54,4 +54,9 @@ defmodule MyAppWeb.Router do
|
||||
end
|
||||
end
|
||||
|
||||
# catch all for serving single page web app
|
||||
scope "/*all", MyAppWeb do
|
||||
get "/", PageController, :index
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
1
mix.exs
1
mix.exs
@@ -46,6 +46,7 @@ defmodule MyApp.Mixfile do
|
||||
{:httpoison, "~> 0.13"},
|
||||
{:dialyxir, "~> 0.5", only: [:dev], runtime: false},
|
||||
{:ex_guard, "~> 1.3", only: :dev},
|
||||
{:cachex, "~> 2.1"},
|
||||
]
|
||||
end
|
||||
|
||||
|
||||
2
mix.lock
2
mix.lock
@@ -1,5 +1,6 @@
|
||||
%{"argon2_elixir": {:hex, :argon2_elixir, "1.2.14", "0fc4bfbc1b7e459954987d3d2f3836befd72d63f3a355e3978f5005dd6e80816", [], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"base64url": {:hex, :base64url, "0.0.1", "36a90125f5948e3afd7be97662a1504b934dd5dac78451ca6e9abf85a10286be", [], [], "hexpm"},
|
||||
"cachex": {:hex, :cachex, "2.1.0", "fad49b4e78d11c6c314e75bd8c9408f5b78cb065c047442798caed10803ee3be", [], [{:eternal, "~> 1.1", [hex: :eternal, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"certifi": {:hex, :certifi, "2.0.0", "a0c0e475107135f76b8c1d5bc7efb33cd3815cb3cf3dea7aefdd174dabead064", [], [], "hexpm"},
|
||||
"comeonin": {:hex, :comeonin, "4.0.3", "4e257dcb748ed1ca2651b7ba24fdbd1bd24efd12482accf8079141e3fda23a10", [], [{:argon2_elixir, "~> 1.2", [hex: :argon2_elixir, repo: "hexpm", optional: true]}, {:bcrypt_elixir, "~> 0.12.1 or ~> 1.0", [hex: :bcrypt_elixir, repo: "hexpm", optional: true]}, {:pbkdf2_elixir, "~> 0.12", [hex: :pbkdf2_elixir, repo: "hexpm", optional: true]}], "hexpm"},
|
||||
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [], [], "hexpm"},
|
||||
@@ -10,6 +11,7 @@
|
||||
"dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [], [], "hexpm"},
|
||||
"ecto": {:hex, :ecto, "2.2.7", "2074106ff4a5cd9cb2b54b12ca087c4b659ddb3f6b50be4562883c1d763fb031", [], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
|
||||
"elixir_make": {:hex, :elixir_make, "0.4.0", "992f38fabe705bb45821a728f20914c554b276838433349d4f2341f7a687cddf", [], [], "hexpm"},
|
||||
"eternal": {:hex, :eternal, "1.2.0", "e2a6b6ce3b8c248f7dc31451aefca57e3bdf0e48d73ae5043229380a67614c41", [], [], "hexpm"},
|
||||
"ex_guard": {:hex, :ex_guard, "1.3.0", "0f5c50b90a7e4c599b45d02448ae53eabffc33adb7bfdfc5f5507715e7662a25", [], [{:fs, "~> 0.9", [hex: :fs, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"fs": {:hex, :fs, "0.9.2", "ed17036c26c3f70ac49781ed9220a50c36775c6ca2cf8182d123b6566e49ec59", [], [], "hexpm"},
|
||||
"gettext": {:hex, :gettext, "0.14.0", "1a019a2e51d5ad3d126efe166dcdf6563768e5d06c32a99ad2281a1fa94b4c72", [], [], "hexpm"},
|
||||
|
||||
5
priv/static/index.html
Normal file
5
priv/static/index.html
Normal file
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
Test 123
|
||||
</body>
|
||||
</html>
|
||||
11
test/myapp_web/controllers/page_controller_test.exs
Normal file
11
test/myapp_web/controllers/page_controller_test.exs
Normal file
@@ -0,0 +1,11 @@
|
||||
defmodule MyAppWeb.PageControllerTest do
|
||||
use MyAppWeb.ConnCase, async: true
|
||||
|
||||
test "index.html should be cached" do
|
||||
assert Cachex.get(:myapp, "index.html") == {:missing, nil}
|
||||
conn = build_conn() |> get("/lsakdjfl")
|
||||
{ok, _} = Cachex.get(:myapp, "index.html")
|
||||
assert ok == :ok
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,6 +1,5 @@
|
||||
defmodule MyAppWeb.ThreadControllerTest do
|
||||
use MyAppWeb.ConnCase, async: true
|
||||
import MyAppWeb.ThreadController
|
||||
import MyApp.Data.TestHelpers
|
||||
|
||||
test "insert new thread should fail" do
|
||||
|
||||
Reference in New Issue
Block a user