Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ Try the Heroku example version so you know what to expect.
#### Browser 📱

Visit: https://phoenix-content-negotiation.herokuapp.com
<!-- see: https://github.com/dwyl/ping -->
![wake-sleeping-heroku-app](https://phoenix-content-negotiation.herokuapp.com/ping)


You should see a random inspiring quote:

Expand Down Expand Up @@ -1604,7 +1607,7 @@ Randomized with seed 452478

### 10. View `JSON` in a Web Browser

Sometimes while you are testing,
Sometimes while you are testing,
you want to view the `JSON` data in Web Browser.
The `content` package allows you to add `.json`
to _any_ route directly in the browser's URL field
Expand All @@ -1622,7 +1625,7 @@ There are two steps to enable this:
get "/*wildcard", QuotesController, :redirect
```

e.g:
e.g:
[`/lib/app_web/router.ex#L21`](https://github.com/dwyl/phoenix-content-negotiation-tutorial/blob/ffaeecd5fc0712631563e37c3315704e1853b68a/lib/app_web/router.ex#L21)


Expand All @@ -1634,13 +1637,13 @@ def redirect(conn, params) do
end
```

e.g:
e.g:
[`/lib/app_web/controllers/quotes_controller.ex#L16-L18`](https://github.com/dwyl/phoenix-content-negotiation-tutorial/blob/ffaeecd5fc0712631563e37c3315704e1853b68a/lib/app_web/controllers/quotes_controller.ex#L16-L18)



You can now visit
[http://localhost:4000/.json](http://localhost:4000/.json)
You can now visit
[http://localhost:4000/.json](http://localhost:4000/.json)
in your web browser
to view a random quote in `JSON` format:

Expand Down
8 changes: 8 additions & 0 deletions lib/app_web/controllers/ping_controller.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule AppWeb.PingController do
use AppWeb, :controller

# see: github.com/dwyl/ping
def ping(conn, params) do
Ping.render_pixel(conn, params)
end
end
1 change: 1 addition & 0 deletions lib/app_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ defmodule AppWeb.Router do
pipe_through :any

get "/", QuotesController, :index
get "/ping", PingController, :ping
get "/*wildcard", QuotesController, :redirect
end
end
3 changes: 3 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ defmodule App.MixProject do
# content negotiation plug: https://github.com/dwyl/content
{:content, "~> 1.3.0"},

# ping to wake the ("Free") Heroku dyno: https://github.com/dwyl/ping
{:ping, "~> 1.0.0"},

# Test Code Coverage:
{:excoveralls, "~> 0.12.2", only: :test}
]
Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.2.1", "274a4b07c4adbdd7785d45a8b0bb57634d0b4f45b18d2c508b26c0344bd59b8f", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "41b4103a2fa282cfd747d377233baf213c648fdcc7928f432937676532490eee"},
"phoenix_live_view": {:hex, :phoenix_live_view, "0.12.1", "42f591c781edbf9fab921319076b7ac635d43aa23e6748d2644563326236d7e4", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.4.16 or ~> 1.5.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14", [hex: :phoenix_html, repo: "hexpm", optional: false]}], "hexpm", "585321e98df1cd5943e370b9784e950a37ca073744eb534660c9048967c52ab6"},
"phoenix_pubsub": {:hex, :phoenix_pubsub, "2.0.0", "a1ae76717bb168cdeb10ec9d92d1480fec99e3080f011402c0a2d68d47395ffb", [:mix], [], "hexpm", "c52d948c4f261577b9c6fa804be91884b381a7f8f18450c5045975435350f771"},
"ping": {:hex, :ping, "1.0.0", "d692c1b8b45fd8ad188c75dfc871639d1e528bcca46b36dccf5cb04c35d7f460", [:mix], [], "hexpm", "e2b2c63e5741827e786674ce7083c3784a51f03bd34237a31364670b51421675"},
"plug": {:hex, :plug, "1.10.1", "c56a6d9da7042d581159bcbaef873ba9d87f15dce85420b0d287bca19f40f9bd", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "b5cd52259817eb8a31f2454912ba1cff4990bca7811918878091cb2ab9e52cb8"},
"plug_cowboy": {:hex, :plug_cowboy, "2.2.2", "7a09aa5d10e79b92d332a288f21cc49406b1b994cbda0fde76160e7f4cc890ea", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e82364b29311dbad3753d588febd7e5ef05062cd6697d8c231e0e007adab3727"},
"plug_crypto": {:hex, :plug_crypto, "1.1.2", "bdd187572cc26dbd95b87136290425f2b580a116d3fb1f564216918c9730d227", [:mix], [], "hexpm", "6b8b608f895b6ffcfad49c37c7883e8df98ae19c6a28113b02aa1e9c5b22d6b5"},
Expand Down
12 changes: 12 additions & 0 deletions test/app_web/controllers/ping_controller_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
defmodule AppWeb.PingControllerTest do
use AppWeb.ConnCase

describe "/ping" do
test "GET /ping (GIF) renders 1x1 pixel", %{conn: conn} do
conn = get(conn, Routes.ping_path(conn, :ping))
assert conn.status == 200
assert conn.state == :sent
assert conn.resp_body =~ <<71, 73, 70, 56, 57>>
end
end
end