From 2f26ed1b970ad1d0b925c42de462388e2ffe7697 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Wed, 22 Jul 2020 18:55:01 +0100 Subject: [PATCH] add /ping to wake Heroku app see: https://github.com/dwyl/ping --- README.md | 1 + lib/auth_web/controllers/ping_controller.ex | 8 ++++++++ lib/auth_web/router.ex | 3 +++ mix.lock | 1 + test/auth_web/controllers/ping_controller_test.exs | 10 ++++++++++ 5 files changed, 23 insertions(+) create mode 100644 lib/auth_web/controllers/ping_controller.ex create mode 100644 test/auth_web/controllers/ping_controller_test.exs diff --git a/README.md b/README.md index 555b2d9c..5b66a9b9 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ you can setup in ***5 minutes***. +![wake-sleeping-heroku-app](https://dwylauth.herokuapp.com/ping) diff --git a/lib/auth_web/controllers/ping_controller.ex b/lib/auth_web/controllers/ping_controller.ex new file mode 100644 index 00000000..b3f59710 --- /dev/null +++ b/lib/auth_web/controllers/ping_controller.ex @@ -0,0 +1,8 @@ +defmodule AuthWeb.PingController do + use AuthWeb, :controller + + # see: github.com/dwyl/ping + def ping(conn, params) do + Ping.render_pixel(conn, params) + end +end \ No newline at end of file diff --git a/lib/auth_web/router.ex b/lib/auth_web/router.ex index 864c19b8..8fb5f35c 100644 --- a/lib/auth_web/router.ex +++ b/lib/auth_web/router.ex @@ -24,6 +24,9 @@ defmodule AuthWeb.Router do # get "/auth/password/new", AuthController, :password_input post "/auth/password/create", AuthController, :password_create post "/auth/password/verify", AuthController, :password_prompt + + # https://github.com/dwyl/ping + get "/ping", PingController, :ping end pipeline :auth do diff --git a/mix.lock b/mix.lock index 2c92a781..737d4801 100644 --- a/mix.lock +++ b/mix.lock @@ -45,6 +45,7 @@ "phoenix_html": {:hex, :phoenix_html, "2.14.2", "b8a3899a72050f3f48a36430da507dd99caf0ac2d06c77529b1646964f3d563e", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "58061c8dfd25da5df1ea0ca47c972f161beb6c875cd293917045b92ffe1bf617"}, "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.2.2", "38d94c30df5e2ef11000697a4fbe2b38d0fbf79239d492ff1be87bbc33bc3a84", [: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", "a3dec3d28ddb5476c96a7c8a38ea8437923408bc88da43e5c45d97037b396280"}, "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.0.0", "a1ae76717bb168cdeb10ec9d92d1480fec99e3080f011402c0a2d68d47395ffb", [:mix], [], "hexpm", "c52d948c4f261577b9c6fa804be91884b381a7f8f18450c5045975435350f771"}, + "ping": {:hex, :ping, "1.0.1", "1f44c7b7151af18627edbd7946a376935871f285fc9c11e9f16ddb1555ea65b5", [:mix], [{:plug, "~> 1.10.1", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "c1421bebcb6601e7fb1158700ca99eb2dc0976b45fe2a26023db5a9318aadfa6"}, "plug": {:hex, :plug, "1.10.3", "c9cebe917637d8db0e759039cc106adca069874e1a9034fd6e3fdd427fd3c283", [: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: false]}], "hexpm", "01f9037a2a1de1d633b5a881101e6a444bcabb1d386ca1e00bb273a1f1d9d939"}, "plug_cowboy": {:hex, :plug_cowboy, "2.3.0", "149a50e05cb73c12aad6506a371cd75750c0b19a32f81866e1a323dda9e0e99d", [: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", "bc595a1870cef13f9c1e03df56d96804db7f702175e4ccacdb8fc75c02a7b97e"}, "plug_crypto": {:hex, :plug_crypto, "1.1.2", "bdd187572cc26dbd95b87136290425f2b580a116d3fb1f564216918c9730d227", [:mix], [], "hexpm", "6b8b608f895b6ffcfad49c37c7883e8df98ae19c6a28113b02aa1e9c5b22d6b5"}, diff --git a/test/auth_web/controllers/ping_controller_test.exs b/test/auth_web/controllers/ping_controller_test.exs new file mode 100644 index 00000000..d6e3192a --- /dev/null +++ b/test/auth_web/controllers/ping_controller_test.exs @@ -0,0 +1,10 @@ +defmodule AuthWeb.PingControllerTest do + use AuthWeb.ConnCase + + 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 \ No newline at end of file