2023-11-17 16:23:40 +00:00
|
|
|
package administration
|
|
|
|
|
|
|
|
import (
|
|
|
|
roadsign "code.smartsheep.studio/goatworks/roadsign/pkg"
|
|
|
|
"fmt"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
2023-11-24 16:34:51 +00:00
|
|
|
"github.com/gofiber/fiber/v2/middleware/basicauth"
|
2023-11-17 16:23:40 +00:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
func InitAdministration() *fiber.App {
|
|
|
|
app := fiber.New(fiber.Config{
|
|
|
|
AppName: "RoadSign Administration",
|
|
|
|
ServerHeader: fmt.Sprintf("RoadSign Administration v%s", roadsign.AppVersion),
|
|
|
|
DisableStartupMessage: true,
|
|
|
|
EnableIPValidation: true,
|
2023-11-18 06:30:35 +00:00
|
|
|
EnablePrintRoutes: viper.GetBool("debug.print_routes"),
|
2023-11-17 16:23:40 +00:00
|
|
|
TrustedProxies: viper.GetStringSlice("security.administration_trusted_proxies"),
|
|
|
|
})
|
|
|
|
|
2023-11-24 16:34:51 +00:00
|
|
|
app.Use(basicauth.New(basicauth.Config{
|
|
|
|
Realm: fmt.Sprintf("RoadSign v%s", roadsign.AppVersion),
|
|
|
|
Authorizer: func(_, password string) bool {
|
|
|
|
return password == viper.GetString("security.credential")
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
2023-11-18 06:30:35 +00:00
|
|
|
webhooks := app.Group("/webhooks").Name("WebHooks")
|
|
|
|
{
|
|
|
|
webhooks.Put("/publish/:site/:upstream", doPublish)
|
|
|
|
}
|
|
|
|
|
2023-11-17 16:23:40 +00:00
|
|
|
return app
|
|
|
|
}
|