2023-12-13 11:52:56 +00:00
|
|
|
package sideload
|
2023-11-17 16:23:40 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-11-25 15:06:23 +00:00
|
|
|
|
|
|
|
roadsign "code.smartsheep.studio/goatworks/roadsign/pkg"
|
2023-11-17 16:23:40 +00:00
|
|
|
"github.com/gofiber/fiber/v2"
|
2023-11-24 16:34:51 +00:00
|
|
|
"github.com/gofiber/fiber/v2/middleware/basicauth"
|
2023-11-25 15:06:23 +00:00
|
|
|
"github.com/gofiber/fiber/v2/middleware/logger"
|
|
|
|
"github.com/rs/zerolog/log"
|
2023-11-17 16:23:40 +00:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
2023-12-13 11:52:56 +00:00
|
|
|
func InitSideload() *fiber.App {
|
2023-11-17 16:23:40 +00:00
|
|
|
app := fiber.New(fiber.Config{
|
2023-12-13 11:52:56 +00:00
|
|
|
AppName: "RoadSign Sideload",
|
|
|
|
ServerHeader: fmt.Sprintf("RoadSign Sideload v%s", roadsign.AppVersion),
|
2023-11-17 16:23:40 +00:00
|
|
|
DisableStartupMessage: true,
|
|
|
|
EnableIPValidation: true,
|
2023-11-18 06:30:35 +00:00
|
|
|
EnablePrintRoutes: viper.GetBool("debug.print_routes"),
|
2023-12-13 11:52:56 +00:00
|
|
|
TrustedProxies: viper.GetStringSlice("security.sideload_trusted_proxies"),
|
2023-12-10 10:15:22 +00:00
|
|
|
BodyLimit: viper.GetInt("hypertext.limitation.max_body_size"),
|
2023-11-17 16:23:40 +00:00
|
|
|
})
|
|
|
|
|
2023-11-30 14:35:40 +00:00
|
|
|
if viper.GetBool("performance.request_logging") {
|
|
|
|
app.Use(logger.New(logger.Config{
|
|
|
|
Output: log.Logger,
|
2023-12-13 11:52:56 +00:00
|
|
|
Format: "[Sideload] [${time}] ${status} - ${latency} ${method} ${path}\n",
|
2023-11-30 14:35:40 +00:00
|
|
|
}))
|
|
|
|
}
|
2023-11-25 15:06:23 +00:00
|
|
|
|
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-12-10 04:30:34 +00:00
|
|
|
cgi := app.Group("/cgi").Name("CGI")
|
|
|
|
{
|
|
|
|
cgi.All("/connectivity", responseConnectivity)
|
|
|
|
}
|
|
|
|
|
2023-11-18 06:30:35 +00:00
|
|
|
webhooks := app.Group("/webhooks").Name("WebHooks")
|
|
|
|
{
|
2023-12-10 10:15:22 +00:00
|
|
|
webhooks.Put("/publish/:site/:slug", doPublish)
|
2023-12-10 10:55:13 +00:00
|
|
|
webhooks.Put("/sync/:slug", doSyncSite)
|
2023-11-18 06:30:35 +00:00
|
|
|
}
|
|
|
|
|
2023-11-17 16:23:40 +00:00
|
|
|
return app
|
|
|
|
}
|