1
0

error50x made into universal error page. Also Error() handler was made that checks for cURL and Wget, and if find, then use built-in plaintext http.Error, and web.errorXXX otherwise.

This commit is contained in:
Alexander Andreev 2023-05-24 23:50:10 +04:00
parent a04adf7fa1
commit 185bd80750
Signed by: Arav
GPG Key ID: D22A817D95815393
3 changed files with 12 additions and 3 deletions

View File

@ -233,6 +233,15 @@ func NotFound(w http.ResponseWriter, r *http.Request) {
} }
} }
func Error(w http.ResponseWriter, r *http.Request, code int, reason string) {
if strings.Contains(r.UserAgent(), "curl") || strings.Contains(r.UserAgent(), "Wget") {
http.Error(w, reason, code)
return
}
web.ErrorXXX(utils.MainSite(r.Host), code, reason, w)
}
func RobotsTxt(w http.ResponseWriter, r *http.Request) { func RobotsTxt(w http.ResponseWriter, r *http.Request) {
data, _ := web.AssetsGetFile("robots.txt") data, _ := web.AssetsGetFile("robots.txt")
w.Write(data) w.Write(data)

View File

@ -1,7 +1,7 @@
extends base.jade extends base.jade
block head block head
:go:func Error50x(mainSite string, code int, errorMsg string) :go:func ErrorXXX(mainSite string, code int, errorMsg string)
style(type="text/css"). style(type="text/css").
#error { #error {
font-size: 3.5rem; font-size: 3.5rem;
@ -12,7 +12,7 @@ block head
#error h1 { font-size: 8rem; } #error h1 { font-size: 8rem; }
block header block header
h1 Internal Server Error h1 Еггог
block body block body
section#error section#error

View File

@ -11,7 +11,7 @@ import (
//go:generate $GOPATH/bin/jade -pkg=web -writer templates/deleted.jade //go:generate $GOPATH/bin/jade -pkg=web -writer templates/deleted.jade
//go:generate $GOPATH/bin/jade -pkg=web -writer templates/uploaded.jade //go:generate $GOPATH/bin/jade -pkg=web -writer templates/uploaded.jade
//go:generate $GOPATH/bin/jade -pkg=web -writer templates/error404.jade //go:generate $GOPATH/bin/jade -pkg=web -writer templates/error404.jade
//go:generate $GOPATH/bin/jade -pkg=web -writer templates/error50x.jade //go:generate $GOPATH/bin/jade -pkg=web -writer templates/errorXXX.jade
//go:embed assets //go:embed assets
var assetsDir embed.FS var assetsDir embed.FS