mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-21 23:22:34 +01:00
feat(api): add configurable landing page at /
Allow server operators to show new players how to install the game client when they visit the server address in a browser. The page content (title and HTML body) is fully configurable via config.json and can be toggled on/off. Uses Go embed for a self-contained dark- themed HTML template with zero new dependencies.
This commit is contained in:
@@ -215,7 +215,12 @@
|
||||
"PatchServer": "",
|
||||
"Banners": [],
|
||||
"Messages": [],
|
||||
"Links": []
|
||||
"Links": [],
|
||||
"LandingPage": {
|
||||
"Enabled": true,
|
||||
"Title": "My Frontier Server",
|
||||
"Content": "<p>Welcome! Download the client from our <a href=\"https://discord.gg/example\">Discord</a>.</p>"
|
||||
}
|
||||
},
|
||||
"Channel": {
|
||||
"Enabled": true
|
||||
|
||||
@@ -254,6 +254,14 @@ type API struct {
|
||||
Banners []APISignBanner
|
||||
Messages []APISignMessage
|
||||
Links []APISignLink
|
||||
LandingPage LandingPage
|
||||
}
|
||||
|
||||
// LandingPage holds config for the browser-facing landing page at /.
|
||||
type LandingPage struct {
|
||||
Enabled bool // Toggle the landing page on/off
|
||||
Title string // Page title (e.g. "My Frontier Server")
|
||||
Content string // Body content — supports raw HTML
|
||||
}
|
||||
|
||||
type APISignBanner struct {
|
||||
|
||||
@@ -63,6 +63,7 @@ func (s *APIServer) Start() error {
|
||||
r.HandleFunc("/character/export", s.ExportSave)
|
||||
r.HandleFunc("/api/ss/bbs/upload.php", s.ScreenShot)
|
||||
r.HandleFunc("/api/ss/bbs/{id}", s.ScreenShotGet)
|
||||
r.HandleFunc("/", s.LandingPage)
|
||||
r.HandleFunc("/health", s.Health)
|
||||
r.HandleFunc("/version", s.Version)
|
||||
handler := handlers.CORS(handlers.AllowedHeaders([]string{"Content-Type"}))(r)
|
||||
|
||||
35
server/api/landing_page.go
Normal file
35
server/api/landing_page.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"html/template"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//go:embed landing_page.html
|
||||
var landingPageHTML string
|
||||
|
||||
var landingPageTmpl = template.Must(template.New("landing").Parse(landingPageHTML))
|
||||
|
||||
type landingPageData struct {
|
||||
Title string
|
||||
Content template.HTML
|
||||
}
|
||||
|
||||
// LandingPage serves a configurable HTML landing page at /.
|
||||
func (s *APIServer) LandingPage(w http.ResponseWriter, r *http.Request) {
|
||||
lp := s.erupeConfig.API.LandingPage
|
||||
if !lp.Enabled {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
data := landingPageData{
|
||||
Title: lp.Title,
|
||||
Content: template.HTML(lp.Content),
|
||||
}
|
||||
if err := landingPageTmpl.Execute(w, data); err != nil {
|
||||
s.logger.Error("Failed to render landing page")
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
24
server/api/landing_page.html
Normal file
24
server/api/landing_page.html
Normal file
@@ -0,0 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{.Title}}</title>
|
||||
<style>
|
||||
*{margin:0;padding:0;box-sizing:border-box}
|
||||
body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;background:#1a1a2e;color:#e0e0e0;min-height:100vh;display:flex;justify-content:center;align-items:center}
|
||||
.container{max-width:640px;width:90%;padding:2.5rem;background:#16213e;border-radius:12px;box-shadow:0 8px 32px rgba(0,0,0,.4)}
|
||||
h1{font-size:1.75rem;margin-bottom:1.5rem;color:#e94560;text-align:center}
|
||||
.content{line-height:1.7}
|
||||
.content a{color:#0f3460;background:#e94560;padding:2px 8px;border-radius:4px;text-decoration:none;font-weight:500}
|
||||
.content a:hover{background:#c73651}
|
||||
.content p{margin-bottom:1rem}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>{{.Title}}</h1>
|
||||
<div class="content">{{.Content}}</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user