perf(web): embed static files and templates
This commit is contained in:
+17
-6
@@ -1,7 +1,13 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/H1K0/SkazaNull/api"
|
||||
"github.com/H1K0/SkazaNull/embed"
|
||||
"github.com/gin-contrib/sessions"
|
||||
"github.com/gin-contrib/sessions/cookie"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -14,14 +20,19 @@ func Serve(addr string, encryptionKey []byte) {
|
||||
store.Options(sessions.Options{Path: "/"})
|
||||
r.Use(sessions.Sessions("session", store))
|
||||
|
||||
tmpl := template.Must(template.ParseFS(embed.TemplatesFS, "templates/*.html"))
|
||||
r.SetHTMLTemplate(tmpl)
|
||||
|
||||
api.RegisterRoutes(r)
|
||||
|
||||
r.LoadHTMLGlob("templates/*.html")
|
||||
|
||||
r.Static("/favicon.ico", "./static/service/favicon.ico")
|
||||
r.Static("/skazanull.webmanifest", "./static/service/skazanull.webmanifest")
|
||||
r.Static("/browserconfig.xml", "./static/service/browserconfig.xml")
|
||||
r.Static("/static", "./static")
|
||||
static, err := fs.Sub(embed.StaticFS, "static")
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to get subs of embedded static FS: %s\n", err)
|
||||
}
|
||||
r.StaticFS("/static/", http.FS(static))
|
||||
r.StaticFileFS("/favicon.ico", "static/service/favicon.ico", http.FS(embed.StaticFS))
|
||||
r.StaticFileFS("/skazanull.webmanifest", "static/service/skazanull.webmanifest", http.FS(embed.StaticFS))
|
||||
r.StaticFileFS("/browserconfig.xml", "static/service/browserconfig.xml", http.FS(embed.StaticFS))
|
||||
|
||||
r.GET("/", api.MiddlewareAuth, root)
|
||||
r.GET("/quotes", api.MiddlewareAuth, middlewareAuth, quotes)
|
||||
|
||||
Reference in New Issue
Block a user