Begin work on outline page and route

This commit is contained in:
joncrangle
2023-11-30 00:57:32 -05:00
parent 97afbaa64d
commit 6749f76b0b
10 changed files with 867 additions and 13 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"embed"
"fmt"
"html/template"
"log"
"os"
"strings"
@@ -14,6 +15,7 @@ import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/basicauth"
"github.com/gofiber/fiber/v2/middleware/favicon"
"github.com/gofiber/template/html/v2"
)
//go:embed favicon.ico
@@ -22,6 +24,9 @@ var faviconData string
//go:embed styles.css
var cssData embed.FS
//go:embed script.js
var scriptData embed.FS
//go:embed VERSION
var version string
@@ -101,12 +106,21 @@ func main() {
*prefork = true
}
engine := html.New("./handlers", ".html")
engine.AddFunc(
// add unescape function
"unescape", func(s string) template.HTML {
return template.HTML(s)
},
)
app := fiber.New(
fiber.Config{
Prefork: *prefork,
GETOnly: false,
ReadBufferSize: 4096 * 4, // increase max header size
DisableStartupMessage: true,
Views: engine,
},
)
@@ -149,6 +163,18 @@ func main() {
return c.Send(cssData)
})
// TODO: move to handlers/script.go
app.Get("/script.js", func(c *fiber.Ctx) error {
scriptData, err := scriptData.ReadFile("script.js")
if err != nil {
return c.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
}
c.Set("Content-Type", "text/javascript")
return c.Send(scriptData)
})
app.Get("ruleset", handlers.Ruleset)
app.Get("raw/*", handlers.Raw)
@@ -158,6 +184,7 @@ func main() {
}
app.Get("api/outline/*", handlers.NewAPIOutlineHandler("api/outline/*", proxyOpts))
app.Get("outline/*", handlers.Outline("outline/*", proxyOpts))
app.Get("/*", handlers.NewProxySiteHandler(proxyOpts))
app.Post("/*", handlers.NewProxySiteHandler(proxyOpts))