Skip to content

Commit 3ac2cc8

Browse files
committed
change error_pages to be disabled by default
1 parent 7f683a9 commit 3ac2cc8

File tree

6 files changed

+29
-16
lines changed

6 files changed

+29
-16
lines changed

config/errorpages.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package config
22

33
// ErrorPages configuration.
44
type ErrorPages struct {
5-
// Disable default error pages.
6-
Disable bool `json:"disable"`
5+
// Enable error pages.
6+
Enable bool `json:"enable"`
77

88
// Dir containing error pages.
99
Dir string `json:"dir"`

docs/04-configuration.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ Date: Mon, 31 Jul 2017 20:49:35 GMT
296296

297297
## Error pages
298298

299-
By default Up will serve a minimalistic error page for requests accepting `text/html`. The following settings are available:
299+
When enabled Up will serve a minimalistic error page for requests accepting `text/html`. The following settings are available:
300300

301-
- `disable` — remove the error page feature and default pages
301+
- `enable` — enable the error page feature
302302
- `dir` — the directory where the error pages are located
303303
- `variables` — vars available to the pages
304304

http/errorpages/errorpages.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,17 @@ func (r *response) Write(b []byte) (int, error) {
8484

8585
// New error pages handler.
8686
func New(c *up.Config, next http.Handler) (http.Handler, error) {
87+
// disabled
88+
if !c.ErrorPages.Enable {
89+
return next, nil
90+
}
91+
92+
// load pages
8793
pages, err := errorpage.Load(c.ErrorPages.Dir)
8894
if err != nil {
8995
return nil, errors.Wrap(err, "loading error pages")
9096
}
9197

92-
// we always have one "default" page, but it can be disabled
93-
if len(pages) == 1 && c.ErrorPages.Disable {
94-
return next, nil
95-
}
96-
9798
h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
9899
mime, _ := accept.Negotiate(r.Header.Get("Accept"), "text/html")
99100

http/errorpages/errorpages_test.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ func TestErrors_templates(t *testing.T) {
4949
os.Chdir("testdata/templates")
5050
defer os.Chdir("../..")
5151

52-
c := &up.Config{Name: "app"}
52+
c := &up.Config{
53+
Name: "app",
54+
ErrorPages: config.ErrorPages{
55+
Enable: true,
56+
},
57+
}
5358
assert.NoError(t, c.Default(), "default")
5459
assert.NoError(t, c.Validate(), "validate")
5560

@@ -60,7 +65,8 @@ func TestErrors_dir(t *testing.T) {
6065
c := &up.Config{
6166
Name: "app",
6267
ErrorPages: config.ErrorPages{
63-
Dir: "testdata/templates",
68+
Dir: "testdata/templates",
69+
Enable: true,
6470
},
6571
}
6672

@@ -74,7 +80,12 @@ func TestErrors_defaults(t *testing.T) {
7480
os.Chdir("testdata/defaults")
7581
defer os.Chdir("../..")
7682

77-
c := &up.Config{Name: "app"}
83+
c := &up.Config{
84+
Name: "app",
85+
ErrorPages: config.ErrorPages{
86+
Enable: true,
87+
},
88+
}
7889
assert.NoError(t, c.Default(), "default")
7990
assert.NoError(t, c.Validate(), "validate")
8091

@@ -90,9 +101,6 @@ func TestErrors_defaults(t *testing.T) {
90101
func TestErrors_disabled(t *testing.T) {
91102
c := &up.Config{
92103
Name: "app",
93-
ErrorPages: config.ErrorPages{
94-
Disable: true,
95-
},
96104
}
97105

98106
assert.NoError(t, c.Default(), "default")

http/inject/inject_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/apex/up"
1111
"github.com/tj/assert"
1212

13+
"github.com/apex/up/config"
1314
"github.com/apex/up/http/errorpages"
1415
"github.com/apex/up/http/static"
1516
"github.com/apex/up/internal/inject"
@@ -21,6 +22,9 @@ func TestInject(t *testing.T) {
2122

2223
c := &up.Config{
2324
Name: "app",
25+
ErrorPages: config.ErrorPages{
26+
Enable: true,
27+
},
2428
Inject: inject.Rules{
2529
"head": []*inject.Rule{
2630
{

internal/cli/deploy/deploy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ retry:
110110
"has_cors": c.CORS != nil,
111111
"has_logs": !c.Logs.Disable,
112112
"has_profile": c.Profile != "",
113-
"has_error_pages": !c.ErrorPages.Disable,
113+
"has_error_pages": c.ErrorPages.Enable,
114114
"app_name_hash": util.Md5(c.Name),
115115
"is_git": commit.Author.Name != "",
116116
})

0 commit comments

Comments
 (0)