Peter Kurfer
82a651cd5d
- replaced previous net/http based muxer and all other components with fiber - replaced polling with SSE to handle file changes - auto-update custom stylesheets - natively support mermaid diagrams - handle custom element attributes for lists properly - reload on config changes - replace JS templating with actual JS code and an API
31 lines
673 B
Go
31 lines
673 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/gofiber/fiber/v2/middleware/filesystem"
|
|
|
|
"github.com/baez90/goveal/assets"
|
|
"github.com/baez90/goveal/fs"
|
|
"github.com/baez90/goveal/web"
|
|
)
|
|
|
|
func RegisterStaticFileHandling(app *fiber.App, wdfs fs.FS) error {
|
|
layers := []fs.FS{wdfs}
|
|
layers = append([]fs.FS{web.WebFS, assets.Assets}, layers...)
|
|
|
|
layeredFS := fs.Layered{Layers: layers}
|
|
fsMiddleware := filesystem.New(filesystem.Config{
|
|
Root: http.FS(layeredFS),
|
|
Next: func(c *fiber.Ctx) bool {
|
|
_, err := layeredFS.Open(strings.TrimLeft(c.Path(), "/"))
|
|
return err != nil
|
|
},
|
|
})
|
|
|
|
app.Use(fsMiddleware)
|
|
|
|
return nil
|
|
}
|