DEVELOPMENT ENVIRONMENT

~liljamo/felu

ref: a3ddc93bdf4330285e00d0a1fc10af5c3801f1a4 felu/internal/routers/frontend.go -rw-r--r-- 2.2 KiB
a3ddc93bJonni Liljamo feat: genTsigKey and refresh tsig key 16 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 * Copyright (C) 2024 Jonni Liljamo <jonni@liljamo.com>
 *
 * This file is licensed under AGPL-3.0-or-later, see NOTICE and LICENSE for
 * more information.
 */

package routers

import (
	"git.src.quest/~liljamo/felu/internal/handlers"
	"git.src.quest/~liljamo/felu/internal/log"
	"git.src.quest/~liljamo/felu/internal/middlewares"
	"git.src.quest/~liljamo/felu/internal/renderer"
	"github.com/alexedwards/scs/v2"
	"github.com/gin-gonic/gin"
)

// SetupFrontendRouter returns the frontend router.
func SetupFrontendRouter(sm *scs.SessionManager) *gin.Engine {
	r := gin.New()
	r.Use(gin.Recovery())
	r.Use(gin.LoggerWithFormatter(func(param gin.LogFormatterParams) string {
		return log.GinFormat(param, "frontend")
	}))
	r.Static("/static", "./static")
	r.HTMLRender = &renderer.TemplRender{}

	r.GET("/", handlers.Index())
	r.GET("/login", middlewares.SessionExists(sm), handlers.Login())

	auth := r.Group("/auth")
	{
		auth.POST("/login", handlers.AuthLogin(sm))
		auth.GET("/logout", handlers.AuthLogout(sm))
	}

	// routes for the actual application frontend
	manage := r.Group("/manage", middlewares.SessionExists(sm))
	{
		manage.GET("/", handlers.Manage())

		manage.GET("/user", handlers.ManageUser())
		manage.POST("/user/password", handlers.PostUserPassword())
		manage.POST("/user/email", handlers.PostUserEmail())
		manage.DELETE("/user", handlers.DeleteUser(sm))

		manage.POST("/domains", handlers.PostDomain())
		manage.PATCH("/domains/:id", handlers.PatchDomain())
		manage.DELETE("/domains/:id", handlers.DeleteDomain())
		manage.POST("/domains/:id/api_key", handlers.RefreshDomainAPIKey())
		manage.POST("/domains/:id/tsig_key", handlers.RefreshDomainTsigKey())

		manage.GET("/partials/domains", handlers.ManagePartialDomains())
	}
	manageAdmin := r.Group("/manage/admin",
		middlewares.SessionExists(sm), middlewares.AdminOnly())
	{
		manageAdmin.GET("/", handlers.ManageAdmin())
		manageAdmin.GET("/users", handlers.ManageAdminUsers())
		manageAdmin.GET("/domains", handlers.ManageAdminDomains())

		manageAdmin.POST("/users", handlers.PostUser())

		manageAdmin.GET("/partials/users_list", handlers.AdminPartialUsersList())
		manageAdmin.GET("/partials/domains_list", handlers.AdminPartialDomainsList())
	}

	return r
}