Skip to content

Commit 1ff6613

Browse files
committed
expand setup instructions #1
1 parent 6bcdcdd commit 1ff6613

File tree

1 file changed

+77
-12
lines changed

1 file changed

+77
-12
lines changed

README.md

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div align="center">
22

3-
# `ping`
3+
# `ping` 🏓
44

55
Easily ping (wake) an idle Heroku App from slumber.
66

@@ -11,17 +11,21 @@ Easily ping (wake) an idle Heroku App from slumber.
1111

1212
</div>
1313

14+
<br />
1415

15-
## Why?
16+
## Why? 🤷
1617

17-
We have _several_ demo/example/tutorial Apps deployed to Heroku.
18-
Apps on the "free" tier go to sleep after **30 minutes** of inactivity.
18+
We have _several_ demo/example/tutorial Apps deployed to Heroku. <br />
19+
Apps on the "free" tier
20+
go to sleep after **30 minutes** of inactivity. <br />
1921
see: https://devcenter.heroku.com/articles/free-dyno-hours
2022

2123
In order to wake them,
2224
we wrote a few lines of code that can be added to any
2325
Elixir/Phoenix App and invoked as an image
2426
in the `README.md` of the project that links to the App.
27+
So the app is ready to go by the time the person
28+
_reading_ the `README.md` clicks on the link. 🔗
2529

2630
We had implemented the "wake from sleep" endpoint
2731
several times in our Heroku Apps,
@@ -32,7 +36,9 @@ After copy-pasting the code a couple of times,
3236
we decided to make it a DRY reusable package
3337
that we can use in our _next_ app(s)!
3438

35-
## What?
39+
<br />
40+
41+
## What? 💡
3642

3743
An easy way for us to wake our Heroku demo apps.
3844

@@ -45,41 +51,100 @@ You can use a _free_ service such as: https://cron-job.org
4551
as described by [Mahdhi Rezvi](https://github.com/Mahdhir) in:
4652
https://medium.com/better-programming/keeping-my-heroku-app-alive-b19f3a8c3a82
4753

54+
<br />
4855

49-
## Who?
56+
## Who? 👤
5057

5158
This package is for anyone building
5259
an Elixir/Phoenix app deployed to Heroku.
5360

61+
<br />
62+
63+
# How? 💻
64+
65+
Add `ping` to your Phoenix App
66+
and use it to wake your Heroku App in 4 easy steps:
5467

55-
# How?
68+
<br />
5669

57-
## 1. Installation
70+
## 1. Installation 📝
5871

5972
Install by adding `ping` to your list of dependencies in `mix.exs`:
6073

6174
```elixir
6275
def deps do
6376
[
64-
{:ping, "~> 1.0.0"}
77+
{:ping, "~> 1.0.0"},
6578
]
6679
end
6780
```
6881

82+
e.g:
83+
[]()
84+
85+
<br />
86+
6987
## 2. Create a `get /ping` Route in your `router.ex`
7088

89+
Open the `router.ex` file of your Phoenix project
90+
and add the following route to your default pipeline:
91+
92+
```elixir
93+
get "/ping", PingController, :ping
94+
```
95+
96+
e.g:
97+
[]()
98+
99+
<br />
71100

101+
## 3. Create the `ping/2` Function in your Controller
72102

103+
```elixir
104+
defmodule AppWeb.PingController do
105+
use AppWeb, :controller
73106

107+
# see: github.com/dwyl/ping
108+
def ping(conn, params) do
109+
Ping.render_pixel(conn, params)
110+
end
111+
end
112+
```
74113

75-
## 3. Create the `ping/2` Function in your Controller
114+
e.g:
115+
[]()
116+
117+
<br />
76118

77119
You can either create a brand new controller,
78-
or use an existing one if you prefer.
120+
or use an existing one if you prefer.
121+
We've created a new controller for clarity/separation.
122+
123+
124+
125+
## 4. Add a `GIF` to the `README.md` of the Heroku App
126+
127+
Add an image linking to the endpoint of the App
128+
to the `README.md` file:
129+
130+
```md
131+
![wake-sleeping-heroku-app](http://localhost:4000/ping)
132+
```
79133

134+
e.g:
135+
[]()
80136

81137

82-
## 4. Add a GIF to the `README.md` of the Heroku App
138+
> The GIF is a _transparent_ 1x1 pixel,
139+
so it's both minimal in size
140+
to minimise response time
141+
and _invisible_ to the person.
142+
The idea is just to make the most basic HTTP request
143+
to the Heroku app in order to wake it.
144+
We don't actually care what is returned.
145+
But we don't want it to `404`
146+
so the person reading the `README.md`
147+
doesn't see an error in their console/browser.
83148

84149

85150

0 commit comments

Comments
 (0)