chore: directory migration - gateway→server, web→client/electron
This commit is contained in:
37
server/internal/static/static.go
Normal file
37
server/internal/static/static.go
Normal file
@ -0,0 +1,37 @@
|
||||
package static
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"sync"
|
||||
)
|
||||
|
||||
//go:embed static
|
||||
var staticFS embed.FS
|
||||
|
||||
var (
|
||||
indexHTML []byte
|
||||
once sync.Once
|
||||
)
|
||||
|
||||
// GetIndex 返回入口页。
|
||||
//
|
||||
// index.html 缺失时回退到 placeholder.html:前端产物不进版本库,
|
||||
// 新克隆里只有占位页。回退而不是报错是故意的 ——
|
||||
// 只改后端的人应当能直接 go run 起来调 API,而不必先装 node。
|
||||
func GetIndex() []byte {
|
||||
once.Do(func() {
|
||||
if data, err := fs.ReadFile(staticFS, "static/index.html"); err == nil {
|
||||
indexHTML = data
|
||||
return
|
||||
}
|
||||
indexHTML, _ = fs.ReadFile(staticFS, "static/placeholder.html")
|
||||
})
|
||||
return indexHTML
|
||||
}
|
||||
|
||||
func Handler() http.Handler {
|
||||
sub, _ := fs.Sub(staticFS, "static")
|
||||
return http.FileServer(http.FS(sub))
|
||||
}
|
||||
70
server/internal/static/static/placeholder.html
Normal file
70
server/internal/static/static/placeholder.html
Normal file
@ -0,0 +1,70 @@
|
||||
<!doctype html>
|
||||
<!--
|
||||
前端未构建时的占位页。
|
||||
|
||||
为什么文件名不是 index.html:那正是 Vite 构建产物的名字。用 index.html 当占位,
|
||||
每次构建后真实产物都会盖掉它并被 git 视为改动;提交进去的 index.html 引用着
|
||||
被忽略的 assets/,新克隆打开就是白屏而不是这张提示页。
|
||||
|
||||
改叫 placeholder.html:构建不会产生这个名字,因此永不被覆盖。
|
||||
static.go 在 index.html 缺失时回退到它。
|
||||
它同时让 go:embed 有文件可嵌 —— 否则新克隆连 go build 都过不去。
|
||||
-->
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<title>AgentMail — 前端未构建</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #f1f5f9;
|
||||
color: #334155;
|
||||
font: 14px/1.7 system-ui, -apple-system, "Segoe UI", sans-serif;
|
||||
}
|
||||
main { max-width: 34rem; padding: 2rem; }
|
||||
h1 { font-size: 1rem; margin: 0 0 0.75rem; }
|
||||
code {
|
||||
background: #e2e8f0;
|
||||
padding: 0.1rem 0.35rem;
|
||||
border-radius: 3px;
|
||||
font-size: 0.85em;
|
||||
}
|
||||
pre {
|
||||
background: #fff;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 6px;
|
||||
padding: 0.75rem 1rem;
|
||||
overflow-x: auto;
|
||||
font-size: 0.85em;
|
||||
}
|
||||
p { margin: 0 0 0.75rem; }
|
||||
.dim { color: #64748b; font-size: 0.9em; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1>AgentMail 前端未构建</h1>
|
||||
<p>
|
||||
当前二进制里没有前端产物。后端 API 仍然可用(<code>/api/v1</code>、
|
||||
<code>/health</code>)。
|
||||
</p>
|
||||
<p>构建并嵌入前端:</p>
|
||||
<pre>sudo ./deploy/install.sh</pre>
|
||||
<p>或者手工:</p>
|
||||
<pre>cd client/electron && npm ci && npm run build
|
||||
cd ../..
|
||||
rm -rf server/internal/static/static/assets
|
||||
cp -r client/electron/dist/. server/internal/static/static/
|
||||
cd server && go build ./cmd/server</pre>
|
||||
<p class="dim">
|
||||
构建产物不进版本库;这个占位文件的存在只是为了让
|
||||
<code>go:embed</code> 在新克隆里能编译通过。
|
||||
</p>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user