Skip to content

Commit 52d44d1

Browse files
committed
v0.2.0 redirect all request to index && cache index page with one year ttl
1 parent 98c8ce9 commit 52d44d1

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ npm-debug.log
4343

4444
.env
4545
.deliver/releases/
46+
47+
.elixir_ls/

config/config.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ import_config "#{Mix.env()}.exs"
3131

3232
config :instaghub,
3333
redis_uri: "redis://localhost:6379",
34-
redis_ttl: 9000
34+
redis_ttl: 31536000

lib/instaghub_web/router.ex

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,21 @@ defmodule InstaghubWeb.Router do
1111
plug :fetch_flash
1212
plug :protect_from_forgery
1313
plug :put_secure_browser_headers
14+
plug :redirect_to_index
1415
plug Cache, []
15-
plug QPS
16-
plug :dec_qps
16+
# plug QPS
17+
# plug :dec_qps
18+
end
19+
20+
def redirect_to_index(%Plug.Conn{request_path: "/" <> path} = conn, _opts) when path != "" do
21+
conn
22+
|> Plug.Conn.put_status(:moved_permanently)
23+
|> Phoenix.Controller.redirect(to: "/")
24+
|> Plug.Conn.halt
25+
end
26+
27+
def redirect_to_index(%Plug.Conn{request_path: "/"} = conn, _opts) do
28+
conn
1729
end
1830

1931
def dec_qps(conn, _opts) do

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule Instaghub.MixProject do
44
def project do
55
[
66
app: :instaghub,
7-
version: "0.1.9",
7+
version: "0.2.0",
88
elixir: "~> 1.5",
99
elixirc_paths: elixirc_paths(Mix.env()),
1010
compilers: [:phoenix, :gettext] ++ Mix.compilers(),

0 commit comments

Comments
 (0)