mirror of
https://github.com/wgh136/nysoure.git
synced 2025-12-16 15:51:14 +00:00
feat: error page
This commit is contained in:
3
go.mod
3
go.mod
@@ -14,8 +14,10 @@ require (
|
|||||||
github.com/blevesearch/bleve v1.0.14
|
github.com/blevesearch/bleve v1.0.14
|
||||||
github.com/chai2010/webp v1.4.0
|
github.com/chai2010/webp v1.4.0
|
||||||
github.com/disintegration/imaging v1.6.2
|
github.com/disintegration/imaging v1.6.2
|
||||||
|
github.com/jlaffaye/ftp v0.2.0
|
||||||
github.com/redis/go-redis/v9 v9.17.0
|
github.com/redis/go-redis/v9 v9.17.0
|
||||||
github.com/stretchr/testify v1.11.1
|
github.com/stretchr/testify v1.11.1
|
||||||
|
github.com/wgh136/cloudflare-error-page v0.0.1
|
||||||
gorm.io/driver/mysql v1.6.0
|
gorm.io/driver/mysql v1.6.0
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -41,7 +43,6 @@ require (
|
|||||||
github.com/golang/snappy v0.0.1 // indirect
|
github.com/golang/snappy v0.0.1 // indirect
|
||||||
github.com/hashicorp/errwrap v1.0.0 // indirect
|
github.com/hashicorp/errwrap v1.0.0 // indirect
|
||||||
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||||
github.com/jlaffaye/ftp v0.2.0 // indirect
|
|
||||||
github.com/mschoch/smat v0.2.0 // indirect
|
github.com/mschoch/smat v0.2.0 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/steveyen/gtreap v0.1.0 // indirect
|
github.com/steveyen/gtreap v0.1.0 // indirect
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -187,6 +187,8 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
|
|||||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||||
github.com/valyala/fasthttp v1.65.0 h1:j/u3uzFEGFfRxw79iYzJN+TteTJwbYkru9uDp3d0Yf8=
|
github.com/valyala/fasthttp v1.65.0 h1:j/u3uzFEGFfRxw79iYzJN+TteTJwbYkru9uDp3d0Yf8=
|
||||||
github.com/valyala/fasthttp v1.65.0/go.mod h1:P/93/YkKPMsKSnATEeELUCkG8a7Y+k99uxNHVbKINr4=
|
github.com/valyala/fasthttp v1.65.0/go.mod h1:P/93/YkKPMsKSnATEeELUCkG8a7Y+k99uxNHVbKINr4=
|
||||||
|
github.com/wgh136/cloudflare-error-page v0.0.1 h1:OZ2JWfEF85JlwSVE71Jx0f+++HkotvZZ1Fb6YUyoFcQ=
|
||||||
|
github.com/wgh136/cloudflare-error-page v0.0.1/go.mod h1:/0dw1xavAlZLFlJla5qeLIh1/hv0irtR8oN7SBVMD8s=
|
||||||
github.com/willf/bitset v1.1.10 h1:NotGKqX0KwQ72NUzqrjZq5ipPNDQex9lo3WpaS8L2sc=
|
github.com/willf/bitset v1.1.10 h1:NotGKqX0KwQ72NUzqrjZq5ipPNDQex9lo3WpaS8L2sc=
|
||||||
github.com/willf/bitset v1.1.10/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
|
github.com/willf/bitset v1.1.10/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
|
||||||
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
|
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v3"
|
"github.com/gofiber/fiber/v3"
|
||||||
|
|
||||||
|
errorpage "github.com/wgh136/cloudflare-error-page"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UnsupportedRegionMiddleware(c fiber.Ctx) error {
|
func UnsupportedRegionMiddleware(c fiber.Ctx) error {
|
||||||
@@ -20,10 +22,39 @@ func UnsupportedRegionMiddleware(c fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if string(c.Request().Header.Peek("Unsupported-Region")) == "true" {
|
if string(c.Request().Header.Peek("Unsupported-Region")) == "true" {
|
||||||
// Return a 403 Forbidden response with an empty html for unsupported regions
|
h, err := generateForbiddenPage(c)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
c.Response().Header.Add("Content-Type", "text/html")
|
c.Response().Header.Add("Content-Type", "text/html")
|
||||||
c.Status(fiber.StatusForbidden)
|
c.Status(fiber.StatusForbidden)
|
||||||
return c.SendString("<html></html>")
|
return c.SendString(h)
|
||||||
}
|
}
|
||||||
return c.Next()
|
return c.Next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func generateForbiddenPage(c fiber.Ctx) (string, error) {
|
||||||
|
params := errorpage.Params{
|
||||||
|
"error_code": 403,
|
||||||
|
"title": "Forbidden",
|
||||||
|
"browser_status": map[string]interface{}{
|
||||||
|
"status": "error",
|
||||||
|
"status_text": "Error",
|
||||||
|
},
|
||||||
|
"cloudflare_status": map[string]interface{}{
|
||||||
|
"status": "ok",
|
||||||
|
"status_text": "Working",
|
||||||
|
},
|
||||||
|
"host_status": map[string]interface{}{
|
||||||
|
"status": "ok",
|
||||||
|
"location": c.Hostname(),
|
||||||
|
},
|
||||||
|
"error_source": "cloudflare",
|
||||||
|
|
||||||
|
"what_happened": "<p>The service is not available in your region.</p>",
|
||||||
|
"what_can_i_do": "<p>Please try again in a few minutes.</p>",
|
||||||
|
"client_ip": c.IP(),
|
||||||
|
}
|
||||||
|
|
||||||
|
return errorpage.Render(params, nil)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user