Add disabling frontend (#137)

* Add disabling frontend

* fixes requested in review

* Document EnableWebFrontEnd in configuration.md
This commit is contained in:
хлифи 2025-02-03 13:16:32 +10:00 committed by GitHub
parent cda9c270f9
commit c16361c6bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 25 deletions

View File

@ -75,6 +75,7 @@ type Config struct {
Domain string
EnableBackgroundEffect bool
EnableFooter bool
EnableWebFrontEnd bool
FallbackAPIServers []FallbackAPIServer
ForwardSkins bool
InstanceName string
@ -123,6 +124,7 @@ func DefaultConfig() Config {
Domain: "",
EnableBackgroundEffect: true,
EnableFooter: true,
EnableWebFrontEnd: true,
ForwardSkins: true,
InstanceName: "Drasl",
ListenAddress: "0.0.0.0:25585",

View File

@ -23,6 +23,7 @@ Other available options:
- `PreMigrationBackups`: Back up the database to `/path/to/StateDirectory/drasl.X.YYYY-mm-ddTHH-MM-SSZ.db` (where `X` is the old database version) before migrating to a new database version. Boolean. Default value: `true`.
- `EnableBackgroundEffect`: Whether to enable the 3D background animation in the web UI. Boolean. Default value: `true`.
- `EnableFooter`: Whether to enable the page footer in the web UI. Boolean. Default value: `true`.
- `EnableWebFrontEnd`: Whether to enable the web UI. Boolean. Default value: `true`.
- `[RateLimit]`: Rate-limit requests per IP address to limit abuse. Only applies to certain web UI routes, not any Yggdrasil routes. Requests for skins, capes, and web pages are also unaffected. Uses [Echo](https://echo.labstack.com)'s [rate limiter middleware](https://echo.labstack.com/middleware/rate-limiter/).
- `Enable`: Boolean. Default value: `true`.
- `RequestsPerSecond`: Number of requests per second allowed per IP address. Integer. Default value: `5`.

56
main.go
View File

@ -144,30 +144,32 @@ func (app *App) MakeServer() *echo.Echo {
}
// Front
t := NewTemplate(app)
e.Renderer = t
e.GET("/", FrontRoot(app))
e.GET("/web/admin", FrontAdmin(app))
e.GET("/web/create-player-challenge", FrontCreatePlayerChallenge(app))
e.GET("/web/manifest.webmanifest", FrontWebManifest(app))
e.GET("/web/player/:uuid", FrontPlayer(app))
e.GET("/web/register-challenge", FrontRegisterChallenge(app))
e.GET("/web/registration", FrontRegistration(app))
frontUser := FrontUser(app)
e.GET("/web/user", frontUser)
e.GET("/web/user/:uuid", frontUser)
e.POST("/web/admin/delete-invite", FrontDeleteInvite(app))
e.POST("/web/admin/new-invite", FrontNewInvite(app))
e.POST("/web/admin/update-users", FrontUpdateUsers(app))
e.POST("/web/create-player", FrontCreatePlayer(app))
e.POST("/web/delete-player", FrontDeletePlayer(app))
e.POST("/web/delete-user", FrontDeleteUser(app))
e.POST("/web/login", FrontLogin(app))
e.POST("/web/logout", FrontLogout(app))
e.POST("/web/register", FrontRegister(app))
e.POST("/web/update-player", FrontUpdatePlayer(app))
e.POST("/web/update-user", FrontUpdateUser(app))
e.Static("/web/public", path.Join(app.Config.DataDirectory, "public"))
if app.Config.EnableWebFrontEnd {
t := NewTemplate(app)
e.Renderer = t
e.GET("/", FrontRoot(app))
e.GET("/web/admin", FrontAdmin(app))
e.GET("/web/create-player-challenge", FrontCreatePlayerChallenge(app))
e.GET("/web/manifest.webmanifest", FrontWebManifest(app))
e.GET("/web/player/:uuid", FrontPlayer(app))
e.GET("/web/register-challenge", FrontRegisterChallenge(app))
e.GET("/web/registration", FrontRegistration(app))
frontUser := FrontUser(app)
e.GET("/web/user", frontUser)
e.GET("/web/user/:uuid", frontUser)
e.POST("/web/admin/delete-invite", FrontDeleteInvite(app))
e.POST("/web/admin/new-invite", FrontNewInvite(app))
e.POST("/web/admin/update-users", FrontUpdateUsers(app))
e.POST("/web/create-player", FrontCreatePlayer(app))
e.POST("/web/delete-player", FrontDeletePlayer(app))
e.POST("/web/delete-user", FrontDeleteUser(app))
e.POST("/web/login", FrontLogin(app))
e.POST("/web/logout", FrontLogout(app))
e.POST("/web/register", FrontRegister(app))
e.POST("/web/update-player", FrontUpdatePlayer(app))
e.POST("/web/update-user", FrontUpdateUser(app))
e.Static("/web/public", path.Join(app.Config.DataDirectory, "public"))
}
e.Static("/web/texture/cape", path.Join(app.Config.StateDirectory, "cape"))
e.Static("/web/texture/default-cape", path.Join(app.Config.StateDirectory, "default-cape"))
e.Static("/web/texture/default-skin", path.Join(app.Config.StateDirectory, "default-skin"))
@ -435,7 +437,11 @@ func setup(config *Config) *App {
log.Fatal(result.Error)
}
}
log.Println("No users found! Here's an invite URL:", Unwrap(app.InviteURL(&invite)))
if app.Config.EnableWebFrontEnd {
log.Println("No users found! Here's an invite URL:", Unwrap(app.InviteURL(&invite)))
} else {
log.Println("No users found! Here's an invite code:", invite.Code)
}
}
}
}