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:
Houmgaor
2026-02-23 20:38:47 +01:00
parent a72ac43f1d
commit 085dc57648
5 changed files with 74 additions and 1 deletions

View File

@@ -215,7 +215,12 @@
"PatchServer": "", "PatchServer": "",
"Banners": [], "Banners": [],
"Messages": [], "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": { "Channel": {
"Enabled": true "Enabled": true

View File

@@ -254,6 +254,14 @@ type API struct {
Banners []APISignBanner Banners []APISignBanner
Messages []APISignMessage Messages []APISignMessage
Links []APISignLink 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 { type APISignBanner struct {

View File

@@ -63,6 +63,7 @@ func (s *APIServer) Start() error {
r.HandleFunc("/character/export", s.ExportSave) r.HandleFunc("/character/export", s.ExportSave)
r.HandleFunc("/api/ss/bbs/upload.php", s.ScreenShot) r.HandleFunc("/api/ss/bbs/upload.php", s.ScreenShot)
r.HandleFunc("/api/ss/bbs/{id}", s.ScreenShotGet) r.HandleFunc("/api/ss/bbs/{id}", s.ScreenShotGet)
r.HandleFunc("/", s.LandingPage)
r.HandleFunc("/health", s.Health) r.HandleFunc("/health", s.Health)
r.HandleFunc("/version", s.Version) r.HandleFunc("/version", s.Version)
handler := handlers.CORS(handlers.AllowedHeaders([]string{"Content-Type"}))(r) handler := handlers.CORS(handlers.AllowedHeaders([]string{"Content-Type"}))(r)

View 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)
}
}

View 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>