Status pages
All checks were successful
release-nightly / build-docker (push) Successful in 1m53s

This commit is contained in:
2024-01-31 15:13:57 +08:00
parent d2710d1718
commit 6607e1dc5e
16 changed files with 291 additions and 73 deletions

View File

@ -0,0 +1,6 @@
package status
import "embed"
//go:embed all:views
var FS embed.FS

View File

@ -0,0 +1,56 @@
package status
import (
roadsign "code.smartsheep.studio/goatworks/roadsign/pkg"
"errors"
"fmt"
"github.com/gofiber/fiber/v2"
"github.com/spf13/viper"
)
type ErrorPayload struct {
Title string `json:"title"`
Message string `json:"message"`
Version string `json:"version"`
}
func StatusPageHandler(c *fiber.Ctx, err error) error {
var reqErr *fiber.Error
var status = fiber.StatusInternalServerError
if errors.As(err, &reqErr) {
status = reqErr.Code
}
c.Status(status)
payload := ErrorPayload{
Version: roadsign.AppVersion,
}
switch status {
case fiber.StatusNotFound:
payload.Title = "Not Found"
payload.Message = fmt.Sprintf("no resource for \"%s\"", c.OriginalURL())
return c.Render("views/not-found", payload)
case fiber.StatusTooManyRequests:
payload.Title = "Request Too Fast"
payload.Message = fmt.Sprintf("you have sent over %d request(s) in a second", viper.GetInt("hypertext.limitation.max_qps"))
return c.Render("views/too-many-requests", payload)
case fiber.StatusRequestEntityTooLarge:
payload.Title = "Request Too Large"
payload.Message = fmt.Sprintf("you have sent a request over %d bytes", viper.GetInt("hypertext.limitation.max_body_size"))
return c.Render("views/request-too-large", payload)
case fiber.StatusBadGateway:
payload.Title = "Backend Down"
payload.Message = fmt.Sprintf("all destnations configured to handle your request are down: %s", err.Error())
return c.Render("views/bad-gateway", payload)
case fiber.StatusGatewayTimeout:
payload.Title = "Backend Took Too Long To Response"
payload.Message = fmt.Sprintf("the destnation took too long to response your request: %s", err.Error())
return c.Render("views/gateway-timeout", payload)
default:
payload.Title = "Oops"
payload.Message = err.Error()
return c.Render("views/fallback", payload)
}
}

View File

@ -0,0 +1,6 @@
<h1 class="text-2xl font-bold">502</h1>
<h2 class="text-lg">No one is standing...</h2>
<div class="mt-3 mx-auto p-5 w-[360px] max-w-screen bg-neutral text-neutral-content rounded">
<code class="capitalize">{{ .Message }}</code>
</div>

View File

@ -0,0 +1,6 @@
<h1 class="text-2xl font-bold">Oops</h1>
<h2 class="text-lg">Something went wrong...</h2>
<div class="mt-3 mx-auto p-5 w-[360px] max-w-screen bg-neutral text-neutral-content rounded">
<code class="capitalize">{{ .Message }}</code>
</div>

View File

@ -0,0 +1,6 @@
<h1 class="text-2xl font-bold">504</h1>
<h2 class="text-lg">Looks like the server in the back fell asleep</h2>
<div class="mt-3 mx-auto p-5 w-[360px] max-w-screen bg-neutral text-neutral-content rounded">
<code class="capitalize">{{ .Message }}</code>
</div>

View File

@ -0,0 +1,83 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/daisyui@4.6.1/dist/full.min.css" rel="stylesheet" type="text/css" />
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
daisyui: {
themes: [
{
light: {
primary: "#4750a3",
secondary: "#93c5fd",
accent: "#0f766e",
info: "#67e8f9",
success: "#15803d",
warning: "#f97316",
error: "#dc2626",
neutral: "#2B3440",
"secondary-content": "oklch(98.71% 0.0106 342.55)",
"neutral-content": "#D7DDE4",
"base-100": "oklch(100% 0 0)",
"base-200": "#F2F2F2",
"base-300": "#E5E6E6",
"base-content": "#1f2937",
"color-scheme": "light",
"--rounded-box": "0",
"--rounded-btn": "0",
"--rounded-badge": "0",
"--tab-radius": "0"
}
},
{
dark: {
primary: "#4750a3",
secondary: "#93c5fd",
accent: "#0f766e",
info: "#67e8f9",
success: "#15803d",
warning: "#f97316",
error: "#dc2626",
neutral: "#2a323c",
"neutral-content": "#A6ADBB",
"base-100": "#1d232a",
"base-200": "#191e24",
"base-300": "#15191e",
"base-content": "#A6ADBB",
"color-scheme": "dark",
"--rounded-box": "0",
"--rounded-btn": "0",
"--rounded-badge": "0",
"--tab-radius": "0"
}
}
]
}
}
</script>
<title>{{ .Title }} | RoadSign</title>
</head>
<body>
<main class="w-full h-screen flex justify-center items-center">
<div class="text-center">
{{embed}}
<footer class="mt-3 text-sm text-neutral">
<p>
Powered by
<a href="https://wiki.smartsheep.studio/roadsign/index.html" target="_blank" class="link link-primary">
RoadSign
</a>
</p>
<p class="text-xs">v{{ .Version }}</p>
</footer>
</div>
</main>
</body>
</html>

View File

@ -0,0 +1,6 @@
<h1 class="text-2xl font-bold">404</h1>
<h2 class="text-lg">Not Found</h2>
<div class="mt-3 mx-auto p-5 w-[360px] max-w-screen bg-neutral text-neutral-content rounded">
<code class="capitalize">{{ .Message }}</code>
</div>

View File

@ -0,0 +1,6 @@
<h1 class="text-2xl font-bold">413</h1>
<h2 class="text-lg">Auh, you are too big.</h2>
<div class="mt-3 mx-auto p-5 w-[360px] max-w-screen bg-neutral text-neutral-content rounded">
<code class="capitalize">{{ .Message }}</code>
</div>

View File

@ -0,0 +1,6 @@
<h1 class="text-2xl font-bold">429</h1>
<h2 class="text-lg">Stop it, you just to fast!</h2>
<div class="mt-3 mx-auto p-5 w-[360px] max-w-screen bg-neutral text-neutral-content rounded">
<code class="capitalize">{{ .Message }}</code>
</div>