use and serve build
This commit is contained in:
parent
acc37d53d8
commit
e762f11257
@ -9,7 +9,7 @@ import (
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
|
||||
"github.com/alice-lg/alice-lg/client"
|
||||
"github.com/alice-lg/alice-lg/ui"
|
||||
)
|
||||
|
||||
// Web Client
|
||||
@ -26,11 +26,11 @@ func (s *Server) webPrepareClientHTML(
|
||||
// Replace paths and tags
|
||||
rewriter := strings.NewReplacer(
|
||||
// Paths
|
||||
"js/", "/static/js/",
|
||||
"css/", "/static/css/",
|
||||
// "js/", "/static/js/",
|
||||
// "css/", "/static/css/",
|
||||
|
||||
// Tags
|
||||
"APP_VERSION", status.Version,
|
||||
"###APP_VERSION###", status.Version,
|
||||
)
|
||||
html = rewriter.Replace(html)
|
||||
return html
|
||||
@ -45,11 +45,11 @@ func (s *Server) webRegisterAssets(
|
||||
log.Println("Preparing and installing assets")
|
||||
|
||||
// Prepare client html: Rewrite paths
|
||||
indexHTMLData, err := client.Assets.ReadFile("build/index.html")
|
||||
indexHTMLData, err := ui.Assets.ReadFile("build/index.html")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
indexHTML := string(indexHTMLData) // TODO: migrate to []byte
|
||||
indexHTML := string(indexHTMLData)
|
||||
|
||||
theme := NewTheme(s.cfg.UI.Theme)
|
||||
err = theme.RegisterThemeAssets(router)
|
||||
@ -61,7 +61,9 @@ func (s *Server) webRegisterAssets(
|
||||
indexHTML = s.webPrepareClientHTML(ctx, indexHTML)
|
||||
|
||||
// Register static assets
|
||||
router.Handler("GET", "/static/*path", client.AssetsHTTPHandler("/static"))
|
||||
router.Handler("GET", "/manifest.json", ui.AssetsHTTPHandler("/"))
|
||||
router.Handler("GET", "/static/*path", ui.AssetsHTTPHandler("/static"))
|
||||
router.Handler("GET", "/assets/*path", ui.AssetsHTTPHandler("/assets"))
|
||||
|
||||
// Rewrite paths
|
||||
// Serve index html as root...
|
||||
|
11
ui/assets.go
11
ui/assets.go
@ -4,6 +4,7 @@ import (
|
||||
"embed"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -17,17 +18,17 @@ func AssetsHTTPHandler(prefix string) http.Handler {
|
||||
handler := http.FileServer(http.FS(Assets))
|
||||
|
||||
return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
|
||||
path := req.URL.Path
|
||||
reqPath := req.URL.Path
|
||||
rawPath := req.URL.RawPath
|
||||
|
||||
if !strings.HasPrefix(path, prefix) {
|
||||
if !strings.HasPrefix(reqPath, prefix) {
|
||||
handler.ServeHTTP(res, req)
|
||||
return
|
||||
}
|
||||
|
||||
// Rewrite path
|
||||
path = "build/" + strings.TrimPrefix(path, prefix)
|
||||
rawPath = "build/" + strings.TrimPrefix(rawPath, prefix)
|
||||
reqPath = path.Join("build/", reqPath)
|
||||
rawPath = path.Join("build/", rawPath)
|
||||
|
||||
// This is pretty much like the StripPrefix middleware,
|
||||
// from net/http, however we replace the prefix with `build/`.
|
||||
@ -36,7 +37,7 @@ func AssetsHTTPHandler(prefix string) http.Handler {
|
||||
req1.URL = new(url.URL)
|
||||
*req1.URL = *req.URL
|
||||
|
||||
req1.URL.Path = path
|
||||
req1.URL.Path = reqPath
|
||||
req1.URL.RawPath = rawPath
|
||||
|
||||
handler.ServeHTTP(res, req1)
|
||||
|
@ -2,6 +2,7 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="alice-version" content="###APP_VERSION###" />
|
||||
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<link rel="stylesheet" href="%PUBLIC_URL%/assets/fonts/source-sans-pro.css" />
|
||||
|
@ -1,3 +0,0 @@
|
||||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
Loading…
x
Reference in New Issue
Block a user