fixup! Add lite webpage

This commit is contained in:
Sebastiaan de Schaetzen 2025-05-22 14:33:02 +02:00
parent 6a415ce878
commit 19292ec746
2 changed files with 18 additions and 1 deletions

View File

@ -0,0 +1,9 @@
<html lang="en">
<head>
<title>Allowance Planner 2000</title>
</head>
<body>
<h1>Allowance Planner 2000</h1>
<h2>Users</h2>
</body>
</html>

View File

@ -578,6 +578,10 @@ func getHistory(c *gin.Context) {
c.IndentedJSON(http.StatusOK, history)
}
func renderLite(c *gin.Context) {
c.HTML(http.StatusOK, "lite.gohtml", nil)
}
/*
Initialises the database, and then starts the server.
If the context gets cancelled, the server is shutdown and the database is closed.
@ -592,6 +596,10 @@ func start(ctx context.Context, config *ServerConfig) {
corsConfig.AllowAllOrigins = true
router.Use(cors.New(corsConfig))
// Web endpoints
router.LoadHTMLFiles("lite.gohtml")
router.GET("/", renderLite)
// API endpoints
router.GET("/api/users", getUsers)
router.GET("/api/user/:userId", getUser)
router.POST("/api/user/:userId/history", postHistory)
@ -641,7 +649,7 @@ func start(ctx context.Context, config *ServerConfig) {
func main() {
config := ServerConfig{
Datasource: os.Getenv("DB_PATH"),
Addr: ":8080",
Addr: ":8081",
}
if config.Datasource == "" {
config.Datasource = "allowance_planner.db3"