mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 07:32:32 +01:00
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.
36 lines
837 B
Go
36 lines
837 B
Go
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)
|
|
}
|
|
}
|