Skip to content

Commit 91609de

Browse files
author
Stan Ansems
committed
Initial commit
0 parents  commit 91609de

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build/
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover/
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps/
9+
10+
# Where third-party dependencies like ExDoc output generated docs.
11+
/doc/
12+
13+
# Ignore .fetch files in case you like to edit your project deps locally.
14+
/.fetch
15+
16+
# If the VM crashes, it generates a dump, let's ignore it too.
17+
erl_crash.dump
18+
19+
# Also ignore archive artifacts (built via "mix archive.build").
20+
*.ez
21+
22+
# Ignore package tarball (built via "mix hex.build").
23+
route_toggle_plug-*.tar

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# RouteTogglePlug
2+
3+
Small plug to toggle routes based on their patch by a environment variable or app config
4+
5+
## Installation
6+
7+
The package can be installed by adding `route_toggle_plug` to your list of dependencies in `mix.exs`:
8+
9+
```elixir
10+
def deps do
11+
[
12+
{:route_toggle_plug, "~> 0.1"}
13+
]
14+
end
15+
```
16+
17+
## Configuration
18+
19+
Add plug
20+
```elixir
21+
22+
plug RouteTogglePlug, paths: ["/docs", "/docs-json"], key: :docs_enabled
23+
24+
```
25+
26+
Configuration to add to config.exs
27+
28+
```elixir
29+
config :route_toggle_plug,
30+
docs_enabled: true
31+
```

lib/route_toggle_plug.ex

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
defmodule RouteTogglePlug do
2+
import Plug.Conn
3+
4+
def init(opts) do
5+
opts
6+
end
7+
8+
def call(conn = %{request_path: path}, paths: paths, key: key) do
9+
if path not in paths || Application.get_env(:route_toggle_plug, key) do
10+
conn
11+
else
12+
conn
13+
|> Plug.Conn.resp(404, "Not found")
14+
|> halt
15+
end
16+
end
17+
18+
def call(conn, _opts) do
19+
conn
20+
end
21+
end

mix.exs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
defmodule RouteTogglePlug.MixProject do
2+
use Mix.Project
3+
4+
def project do
5+
[
6+
app: :route_toggle_plug,
7+
version: "0.1",
8+
elixir: "~> 1.9",
9+
start_permanent: Mix.env() == :prod,
10+
description: description(),
11+
package: package(),
12+
deps: deps(),
13+
name: "RouteTogglePlug",
14+
source_url: "https://github.com/StanAnsems/RouteTogglePlug"
15+
]
16+
end
17+
18+
def application, do: []
19+
20+
defp deps do
21+
[
22+
{:ex_doc, "~> 0.19", only: :dev, runtime: false}
23+
]
24+
end
25+
26+
defp description() do
27+
"Small plug to toggle routes based on their patch by a environment variable or app config"
28+
end
29+
30+
defp package() do
31+
[
32+
files: ["lib", "mix.exs", "README.md"],
33+
licenses: ["MIT"],
34+
links: %{"GitHub" => "https://github.com/StanAnsems/RouteTogglePlug"}
35+
]
36+
end
37+
end

0 commit comments

Comments
 (0)