fix(dev): load runtime metadata without frontend build artifacts
This commit is contained in:
1 parent
c705d1ab33
commit
11f5e4fcf4
6 files changed
+96
-16
No files matched your search
@@ -5,7 +5,9 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"embed"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
)
|
||||
|
||||
@@ -19,3 +21,19 @@ func Dist() fs.FS {
|
||||
}
|
||||
return sub
|
||||
}
|
||||
|
||||
// BuildVersion 与页面入口使用同一构建标识,生产产物缺失时明确失败。
|
||||
func BuildVersion() (string, error) {
|
||||
html, err := fs.ReadFile(Dist(), "index.html")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
marker := []byte(`<meta name="rawmark-version" content="`)
|
||||
if start := bytes.Index(html, marker); start >= 0 {
|
||||
rest := html[start+len(marker):]
|
||||
if end := bytes.IndexByte(rest, '"'); end > 0 {
|
||||
return string(rest[:end]), nil
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("缺少构建版本")
|
||||
}
|
||||
Reference in new issue
Block a user