Update documentation for custom error pages (#2630)
* Update documentation for custom error pages * custom-error-pages: Fix path to error pages Bump version to 0.2
This commit is contained in:
parent
306910d956
commit
55679aa268
9 changed files with 1945 additions and 148 deletions
|
|
@ -3,7 +3,7 @@ all: all-container
|
|||
BUILDTAGS=
|
||||
|
||||
# Use the 0.0 tag for testing, it shouldn't clobber any release builds
|
||||
TAG?=0.1
|
||||
TAG?=0.2
|
||||
REGISTRY?=quay.io/kubernetes-ingress-controller
|
||||
GOOS?=linux
|
||||
DOCKER?=docker
|
||||
|
|
|
|||
|
|
@ -1,2 +1,3 @@
|
|||
# custom-error-pages
|
||||
|
||||
Example of Custom error pages for the NGINX Ingress controller
|
||||
|
|
|
|||
|
|
@ -39,15 +39,19 @@ const (
|
|||
|
||||
// ContentType name of the header that defines the format of the reply
|
||||
ContentType = "Content-Type"
|
||||
|
||||
// ErrFilesPathVar is the name of the environment variable indicating
|
||||
// the location on disk of files served by the handler.
|
||||
ErrFilesPathVar = "ERROR_FILES_PATH"
|
||||
)
|
||||
|
||||
func main() {
|
||||
path := "/www"
|
||||
if os.Getenv("PATH") != "" {
|
||||
path = os.Getenv("PATH")
|
||||
errFilesPath := "/www"
|
||||
if os.Getenv(ErrFilesPathVar) != "" {
|
||||
errFilesPath = os.Getenv(ErrFilesPathVar)
|
||||
}
|
||||
|
||||
http.HandleFunc("/", errorHandler(path))
|
||||
http.HandleFunc("/", errorHandler(errFilesPath))
|
||||
|
||||
http.Handle("/metrics", promhttp.Handler())
|
||||
|
||||
|
|
@ -66,15 +70,14 @@ func errorHandler(path string) func(http.ResponseWriter, *http.Request) {
|
|||
format := r.Header.Get(FormatHeader)
|
||||
if format == "" {
|
||||
format = "text/html"
|
||||
log.Printf("forma not specified. Using %v\n", format)
|
||||
log.Printf("format not specified. Using %v", format)
|
||||
}
|
||||
|
||||
mediaType, _, _ := mime.ParseMediaType(format)
|
||||
cext, err := mime.ExtensionsByType(mediaType)
|
||||
cext, err := mime.ExtensionsByType(format)
|
||||
if err != nil {
|
||||
log.Printf("unexpected error reading media type extension: %v. Using %v\n", err, ext)
|
||||
log.Printf("unexpected error reading media type extension: %v. Using %v", err, ext)
|
||||
} else if len(cext) == 0 {
|
||||
log.Printf("couldn't get media type extension. Using %v\n", ext)
|
||||
log.Printf("couldn't get media type extension. Using %v", ext)
|
||||
} else {
|
||||
ext = cext[0]
|
||||
}
|
||||
|
|
@ -84,7 +87,7 @@ func errorHandler(path string) func(http.ResponseWriter, *http.Request) {
|
|||
code, err := strconv.Atoi(errCode)
|
||||
if err != nil {
|
||||
code = 404
|
||||
log.Printf("unexpected error reading return code: %v. Using %v\n", err, code)
|
||||
log.Printf("unexpected error reading return code: %v. Using %v", err, code)
|
||||
}
|
||||
w.WriteHeader(code)
|
||||
|
||||
|
|
@ -94,22 +97,22 @@ func errorHandler(path string) func(http.ResponseWriter, *http.Request) {
|
|||
file := fmt.Sprintf("%v/%v%v", path, code, ext)
|
||||
f, err := os.Open(file)
|
||||
if err != nil {
|
||||
log.Printf("unexpected error opening file: %v\n", err)
|
||||
log.Printf("unexpected error opening file: %v", err)
|
||||
scode := strconv.Itoa(code)
|
||||
file := fmt.Sprintf("%v/%cxx%v", path, scode[0], ext)
|
||||
f, err := os.Open(file)
|
||||
if err != nil {
|
||||
log.Printf("unexpected error opening file: %v\n", err)
|
||||
log.Printf("unexpected error opening file: %v", err)
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
log.Printf("serving custom error response for code %v and format %v from file %v\n", code, format, file)
|
||||
log.Printf("serving custom error response for code %v and format %v from file %v", code, format, file)
|
||||
io.Copy(w, f)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
log.Printf("serving custom error response for code %v and format %v from file %v\n", code, format, file)
|
||||
log.Printf("serving custom error response for code %v and format %v from file %v", code, format, file)
|
||||
io.Copy(w, f)
|
||||
|
||||
duration := time.Now().Sub(start).Seconds()
|
||||
|
|
|
|||
1830
images/custom-error-pages/rootfs/etc/mime.types
Normal file
1830
images/custom-error-pages/rootfs/etc/mime.types
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue