heroku_error_pages 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/README.md +50 -11
- data/lib/heroku_error_pages/config.rb +4 -6
- data/lib/heroku_error_pages/page_config.rb +3 -4
- data/lib/heroku_error_pages/renderer.rb +7 -6
- data/lib/heroku_error_pages/version.rb +1 -1
- data/lib/heroku_error_pages.rb +19 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b985d20291623223aec9fe97d81b3171aa432257116cd01c841383a03a3bf11
|
4
|
+
data.tar.gz: b61f8ef5c37a87f836d9aa338cdb167d1e1066dd476446ee4578189071e5fad9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95ceb34bb2908d5a5e65cc0b386de1531ca92c9f59e4cf6c400443e68315bf9b1fe351ff3e0abf97ecad35fd004156e1d71f9d0f8d94f5b628f0c0d338e82146
|
7
|
+
data.tar.gz: 8570c4cf61a9820ce034df71ab183e760f8910a8cdf640342f0169bd3f238aadd956276026a8d40262b7ea829b3614ca28b7063e793a3f53ca258a1f7b308ef8
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
# HerokuErrorPages
|
2
2
|
|
3
|
-
Heroku allows you to configure custom error pages
|
3
|
+
Heroku allows you to configure [custom error pages](https://devcenter.heroku.com/articles/error-pages#customize-pages) for application errors and maintenance mode.
|
4
4
|
|
5
|
-
This gem allows you to
|
5
|
+
This gem allows you to developer the pages in your Rails application, generate the pages during Heroku deployments, and store the static HTML on Amazon S3. This means your custom error pages are always kept up-to-date.
|
6
6
|
|
7
|
-
|
7
|
+
There are 3 areas of configuration:
|
8
|
+
- Gem Installation and Configuration
|
9
|
+
- AWS Configuration
|
10
|
+
- Heroku Configuration
|
11
|
+
|
12
|
+
## Gem Installation
|
8
13
|
|
9
14
|
Install the gem and add to the application's Gemfile by executing:
|
10
15
|
|
@@ -14,9 +19,9 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
14
19
|
|
15
20
|
$ gem install heroku_error_pages
|
16
21
|
|
17
|
-
##
|
22
|
+
## Gem Configuration
|
18
23
|
|
19
|
-
Configure the error and/or maintenance pages
|
24
|
+
Configure the error and/or maintenance pages via an initializer in `config/initializers/heroku_error_pages.rb`.
|
20
25
|
|
21
26
|
Sample configuration:
|
22
27
|
|
@@ -32,12 +37,11 @@ HerokuErrorPages.configure do |config|
|
|
32
37
|
|
33
38
|
# at least one page must be configured
|
34
39
|
config.configure_error_page(
|
35
|
-
s3_path: 'application_error.html', # where the html will be stored in your S3 bucket
|
36
40
|
template: 'errors/show', # the Rails template to render
|
37
41
|
assigns: { # optional, any variables to assign to the template
|
38
42
|
status: :internal_server_error
|
39
43
|
},
|
40
|
-
|
44
|
+
layout: 'public' # optional, defaults to 'application'
|
41
45
|
)
|
42
46
|
|
43
47
|
config.configure_maintenance_page(
|
@@ -46,20 +50,55 @@ HerokuErrorPages.configure do |config|
|
|
46
50
|
end
|
47
51
|
```
|
48
52
|
|
49
|
-
|
53
|
+
## AWS Configuration
|
54
|
+
|
55
|
+
The AWS user specified in the configuration must have `s3:PutObject` permissions for the specified AWS S3 bucket. The gem does not specify any ACLs for the uploaded files, so the bucket policy must allow public access to the files.
|
56
|
+
|
57
|
+
The gem prefixes all files with `heroku_error_pages/` to avoid conflicts with other files in the bucket. You can therefore apply a single bucket policy to allow public access to only the files with this prefix.
|
58
|
+
|
59
|
+
This example policy will allow public access to all files with the prefix `heroku_error_pages/` (make sure you replace `YOUR_BUCKET_NAME_HERE` with your actual bucket name):
|
60
|
+
|
61
|
+
```
|
62
|
+
{
|
63
|
+
"Version": "2012-10-17",
|
64
|
+
"Statement": [
|
65
|
+
{
|
66
|
+
"Sid": "AllowPublicReadForHerokuErrorPages",
|
67
|
+
"Effect": "Allow",
|
68
|
+
"Principal": "*",
|
69
|
+
"Action": "s3:GetObject",
|
70
|
+
"Resource": "arn:aws:s3:::YOUR_BUCKET_NAME_HERE/heroku_error_pages/*"
|
71
|
+
}
|
72
|
+
]
|
73
|
+
```
|
74
|
+
|
75
|
+
In order to use a policy for allowing public access, configure your bucket like this:
|
76
|
+
|
77
|
+
- ☑️ Block public access to buckets and objects granted through new access control lists (ACLs)
|
78
|
+
- ☑️ Block public access to buckets and objects granted through any access control lists (ACLs)
|
79
|
+
- ⬜ Block public access to buckets and objects granted through new public bucket or access point policies
|
80
|
+
- ⬜ Block public and cross-account access to buckets and objects through any public bucket or access point policies
|
81
|
+
|
82
|
+
## Heroku Configuration
|
83
|
+
|
84
|
+
Configure the Heroku `Procfile` to deploy your custom pages as part of deployments:
|
50
85
|
|
51
86
|
```
|
52
87
|
release: bundle exec rake heroku_error_pages:deploy
|
53
88
|
```
|
54
89
|
|
55
|
-
|
90
|
+
This rake task will generate `error_page.html` and/or `maintenance_page.html` and upload all the relevant assets (CSS, JS, images) to the S3 bucket in the `heroku_error_pages/` folder/prefix. This should ensure that the custom error pages have all assets referenced correctly via relative paths.
|
91
|
+
|
92
|
+
You can verify that your error pages have the necessary permissions and are being served correctly out of S3 by navigating there in your browser, i.e. `https://your-s3-bucket.s3.amazonaws.com/heroku_error_pages/error_page.html` or `https://your-s3-bucket.s3.amazonaws.com/heroku_error_pages/maintenance_page.html`. Once you are satisfied you can configure Heroku to use your custom error pages:
|
56
93
|
|
57
94
|
```
|
58
95
|
heroku config:set \
|
59
|
-
ERROR_PAGE_URL=//your-s3-bucket.s3.amazonaws.com/
|
60
|
-
MAINTENANCE_PAGE_URL=//your-s3-bucket.s3.amazonaws.com/
|
96
|
+
ERROR_PAGE_URL=//your-s3-bucket.s3.amazonaws.com/heroku_error_pages/error_page.html \
|
97
|
+
MAINTENANCE_PAGE_URL=//your-s3-bucket.s3.amazonaws.com/heroku_error_pages/maintenance_page.html
|
61
98
|
```
|
62
99
|
|
100
|
+
The pages will be refreshed automatically as part of every deployment, which ensures that any style changes are automatically applied.
|
101
|
+
|
63
102
|
## Development
|
64
103
|
|
65
104
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -11,21 +11,19 @@ module HerokuErrorPages
|
|
11
11
|
@aws_region = "us-east-1"
|
12
12
|
end
|
13
13
|
|
14
|
-
def configure_error_page(
|
14
|
+
def configure_error_page(template:, assigns: nil, layout: nil)
|
15
15
|
@error_page = PageConfig.new(
|
16
|
-
s3_path: s3_path,
|
17
16
|
template: template,
|
18
17
|
assigns: assigns,
|
19
|
-
|
18
|
+
layout: layout
|
20
19
|
)
|
21
20
|
end
|
22
21
|
|
23
|
-
def
|
22
|
+
def configure_maintenance_page(template:, assigns: nil, layout: nil)
|
24
23
|
@maintenance_page = PageConfig.new(
|
25
|
-
s3_path: s3_path,
|
26
24
|
template: template,
|
27
25
|
assigns: assigns,
|
28
|
-
|
26
|
+
layout: layout
|
29
27
|
)
|
30
28
|
end
|
31
29
|
end
|
@@ -2,13 +2,12 @@
|
|
2
2
|
|
3
3
|
module HerokuErrorPages
|
4
4
|
class PageConfig
|
5
|
-
attr_accessor :
|
5
|
+
attr_accessor :template, :assigns, :layout
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@s3_path = s3_path
|
7
|
+
def initialize(template:, assigns:, layout:)
|
9
8
|
@template = template
|
10
9
|
@assigns = assigns || {}
|
11
|
-
@
|
10
|
+
@layout = layout || "application"
|
12
11
|
end
|
13
12
|
end
|
14
13
|
end
|
@@ -4,14 +4,14 @@ module HerokuErrorPages
|
|
4
4
|
class Renderer
|
5
5
|
class << self
|
6
6
|
def render_html(page_config)
|
7
|
-
new(page_config.template, page_config.assigns, page_config.
|
7
|
+
new(page_config.template, page_config.assigns, page_config.layout).html
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
def initialize(template, assigns,
|
11
|
+
def initialize(template, assigns, layout)
|
12
12
|
@template = template
|
13
13
|
@assigns = assigns
|
14
|
-
@
|
14
|
+
@layout = layout
|
15
15
|
end
|
16
16
|
|
17
17
|
def html
|
@@ -20,14 +20,15 @@ module HerokuErrorPages
|
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
-
attr_reader :template, :assigns, :
|
23
|
+
attr_reader :template, :assigns, :layout
|
24
24
|
|
25
25
|
def generate_html
|
26
|
-
controller = Class.new(
|
26
|
+
controller = Class.new(ActionController::Base) do
|
27
27
|
self.asset_host = nil
|
28
|
+
self.relative_url_root = "/#{HerokuErrorPages::S3_PREFIX}"
|
28
29
|
end
|
29
30
|
|
30
|
-
controller.render(template: template, assigns: assigns)
|
31
|
+
controller.render(template: template, assigns: assigns, layout: layout)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
data/lib/heroku_error_pages.rb
CHANGED
@@ -6,8 +6,13 @@ require_relative "heroku_error_pages/page_config"
|
|
6
6
|
require_relative "heroku_error_pages/railtie"
|
7
7
|
require_relative "heroku_error_pages/renderer"
|
8
8
|
require_relative "heroku_error_pages/public_asset"
|
9
|
+
require "aws-sdk-s3"
|
9
10
|
|
10
11
|
module HerokuErrorPages
|
12
|
+
S3_PREFIX = "heroku_error_pages"
|
13
|
+
ERROR_PAGE = "error_page.html"
|
14
|
+
MAINTENANCE_PAGE = "maintenance_page.html"
|
15
|
+
|
11
16
|
class << self
|
12
17
|
def config
|
13
18
|
@config ||= Config.new
|
@@ -28,19 +33,22 @@ module HerokuErrorPages
|
|
28
33
|
region: config.aws_region
|
29
34
|
)
|
30
35
|
|
31
|
-
deploy_page(config.error_page, s3_client)
|
32
|
-
deploy_page(config.maintenance_page, s3_client)
|
36
|
+
deploy_page(config.error_page, s3_client, "error_page.html")
|
37
|
+
deploy_page(config.maintenance_page, s3_client, "maintenance_page.html")
|
33
38
|
deploy_public_assets(s3_client)
|
34
39
|
end
|
35
40
|
|
36
41
|
private
|
37
42
|
|
38
|
-
def deploy_page(page_config, s3_client)
|
43
|
+
def deploy_page(page_config, s3_client, page_name)
|
39
44
|
return if page_config.nil?
|
40
45
|
|
41
|
-
s3_object = Aws::S3::Object.new(
|
46
|
+
s3_object = Aws::S3::Object.new(
|
47
|
+
config.s3_bucket_name,
|
48
|
+
"#{S3_PREFIX}/#{page_name}",
|
49
|
+
client: s3_client
|
50
|
+
)
|
42
51
|
s3_object.put(
|
43
|
-
acl: "public-read",
|
44
52
|
body: Renderer.render_html(page_config),
|
45
53
|
content_type: "text/html"
|
46
54
|
)
|
@@ -48,13 +56,16 @@ module HerokuErrorPages
|
|
48
56
|
|
49
57
|
def deploy_public_assets(s3_client)
|
50
58
|
PublicAsset.all.each do |public_asset|
|
51
|
-
s3_absolute_path = "#{config.s3_bucket_name}/#{public_asset.relative_path}"
|
59
|
+
s3_absolute_path = "#{config.s3_bucket_name}/#{S3_PREFIX}/#{public_asset.relative_path}"
|
52
60
|
Rails.logger.info "Uploading #{public_asset.absolute_path} to #{s3_absolute_path}"
|
53
61
|
|
54
|
-
s3_object = Aws::S3::Object.new(
|
62
|
+
s3_object = Aws::S3::Object.new(
|
63
|
+
config.s3_bucket_name,
|
64
|
+
"#{S3_PREFIX}/#{public_asset.relative_path}",
|
65
|
+
client: s3_client
|
66
|
+
)
|
55
67
|
s3_object.upload_file(
|
56
68
|
public_asset.absolute_path,
|
57
|
-
acl: "public-read",
|
58
69
|
content_type: public_asset.mime_type
|
59
70
|
)
|
60
71
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heroku_error_pages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jaco Pretorius
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-04-
|
10
|
+
date: 2025-04-20 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: aws-sdk-s3
|