add a bunch of frontend stuff

This commit is contained in:
sam 2023-09-03 04:11:56 +02:00
parent 2586161abd
commit bc85b7c340
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
30 changed files with 1459 additions and 136 deletions

View file

@ -1,22 +1,26 @@
package frontend
import (
"embed"
"html/template"
"net/http"
"os"
"path/filepath"
"git.sleepycat.moe/sam/mercury/frontend"
"git.sleepycat.moe/sam/mercury/internal/database"
"git.sleepycat.moe/sam/mercury/web/app"
"github.com/go-chi/chi/v5"
"github.com/rs/zerolog/log"
vueglue "github.com/torenware/vite-go"
_ "embed"
)
//go:embed app.html
var htmlTemplate string
//go:embed assets
var assets embed.FS
type Frontend struct {
*app.App
glue *vueglue.VueGlue
@ -94,3 +98,14 @@ func (app *Frontend) ServeFrontend(w http.ResponseWriter, r *http.Request) {
log.Err(err).Msg("executing frontend template")
}
}
func (app *Frontend) ServeStaticAssets(w http.ResponseWriter, r *http.Request) {
if app.Config.Core.Dev {
// TODO: this is unsafe
path := filepath.Join("web/frontend/assets/", chi.URLParam(r, "*"))
http.ServeFile(w, r, path)
return
}
_ = assets
}