Skip to content

Commit

Permalink
change error_pages to be disabled by default
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Nov 21, 2019
1 parent 7f683a9 commit 3ac2cc8
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
4 changes: 2 additions & 2 deletions config/errorpages.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package config

// ErrorPages configuration.
type ErrorPages struct {
// Disable default error pages.
Disable bool `json:"disable"`
// Enable error pages.
Enable bool `json:"enable"`

// Dir containing error pages.
Dir string `json:"dir"`
Expand Down
4 changes: 2 additions & 2 deletions docs/04-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ Date: Mon, 31 Jul 2017 20:49:35 GMT

## Error pages

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

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

Expand Down
11 changes: 6 additions & 5 deletions http/errorpages/errorpages.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,17 @@ func (r *response) Write(b []byte) (int, error) {

// New error pages handler.
func New(c *up.Config, next http.Handler) (http.Handler, error) {
// disabled
if !c.ErrorPages.Enable {
return next, nil
}

// load pages
pages, err := errorpage.Load(c.ErrorPages.Dir)
if err != nil {
return nil, errors.Wrap(err, "loading error pages")
}

// we always have one "default" page, but it can be disabled
if len(pages) == 1 && c.ErrorPages.Disable {
return next, nil
}

h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
mime, _ := accept.Negotiate(r.Header.Get("Accept"), "text/html")

Expand Down
20 changes: 14 additions & 6 deletions http/errorpages/errorpages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ func TestErrors_templates(t *testing.T) {
os.Chdir("testdata/templates")
defer os.Chdir("../..")

c := &up.Config{Name: "app"}
c := &up.Config{
Name: "app",
ErrorPages: config.ErrorPages{
Enable: true,
},
}
assert.NoError(t, c.Default(), "default")
assert.NoError(t, c.Validate(), "validate")

Expand All @@ -60,7 +65,8 @@ func TestErrors_dir(t *testing.T) {
c := &up.Config{
Name: "app",
ErrorPages: config.ErrorPages{
Dir: "testdata/templates",
Dir: "testdata/templates",
Enable: true,
},
}

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

c := &up.Config{Name: "app"}
c := &up.Config{
Name: "app",
ErrorPages: config.ErrorPages{
Enable: true,
},
}
assert.NoError(t, c.Default(), "default")
assert.NoError(t, c.Validate(), "validate")

Expand All @@ -90,9 +101,6 @@ func TestErrors_defaults(t *testing.T) {
func TestErrors_disabled(t *testing.T) {
c := &up.Config{
Name: "app",
ErrorPages: config.ErrorPages{
Disable: true,
},
}

assert.NoError(t, c.Default(), "default")
Expand Down
4 changes: 4 additions & 0 deletions http/inject/inject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/apex/up"
"github.com/tj/assert"

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

c := &up.Config{
Name: "app",
ErrorPages: config.ErrorPages{
Enable: true,
},
Inject: inject.Rules{
"head": []*inject.Rule{
{
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ retry:
"has_cors": c.CORS != nil,
"has_logs": !c.Logs.Disable,
"has_profile": c.Profile != "",
"has_error_pages": !c.ErrorPages.Disable,
"has_error_pages": c.ErrorPages.Enable,
"app_name_hash": util.Md5(c.Name),
"is_git": commit.Author.Name != "",
})
Expand Down

0 comments on commit 3ac2cc8

Please sign in to comment.