package main

import (
	"github.com/pocketbase/pocketbase"
	"github.com/pocketbase/pocketbase/apis"
	"github.com/pocketbase/pocketbase/core"
	"log"
	"os"
	"strings"
)

func main() {
	app := pocketbase.New()

	app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
		// add new "GET /hello" route to the app router (echo)
		e.Router.GET("/*", apis.StaticDirectoryHandler(os.DirFS("./pb_public"), false))
		return nil
	})

	app.OnFileDownloadRequest().Add(func(e *core.FileDownloadEvent) error {

		if strings.HasSuffix(e.ServedPath, ".html") {
			e.HttpContext.Response().Header().Set("Content-Disposition", "inline")
			e.HttpContext.Response().Header().Set("Content-Security-Policy", "")
		}
		log.Println(e.ServedPath)
		log.Println(e.HttpContext)
		return nil
	})

	if err := app.Start(); err != nil {
		log.Fatal(err)
	}
}
