fix(web): preserve asset paths behind root proxy
This commit is contained in:
@@ -572,7 +572,7 @@ func TestUsageResourceServesFeatureModules(t *testing.T) {
|
||||
if pageResponse.StatusCode != http.StatusOK || !strings.Contains(page, `data-view="logs">日志`) {
|
||||
t.Fatalf("unexpected UI response: status=%d", pageResponse.StatusCode)
|
||||
}
|
||||
for _, feature := range []string{`<body class="read-only">`, `id="demo-perspective" class="demo-perspective hidden"`, `data-perspective="admin">管理员示教`, `data-perspective="user">普通用户视角`, `data-view="stats">统计`, `data-view="users">用户`, `id="view-users" class="view admin-only"`, `id="quota-chart"`, `id="page-buttons" class="page-buttons admin-only"`, `id="user-usage"`, `id="usage-filter-panel" class="usage-filter-panel admin-only"`, `id="refresh" class="admin-only"`, `id="editor-quota"`, `id="billing-ledger"`, `id="key-management" class="user-management"`, `id="reset-all-billing"`, `id="key-rows" class="user-card-grid"`, `class="surface price-panel price-layout"`, `src="./ui-config.js"`, `type="module" src="./app/main.js"`, `href="./styles/base.css"`, `href="./styles/keys.css"`, `href="./styles/usage.css"`, `href="./styles/pricing.css"`} {
|
||||
for _, feature := range []string{`<body class="read-only">`, `<base href="/v0/resource/plugins/billing/">`, `id="demo-perspective" class="demo-perspective hidden"`, `data-perspective="admin">管理员示教`, `data-perspective="user">普通用户视角`, `data-view="stats">统计`, `data-view="users">用户`, `id="view-users" class="view admin-only"`, `id="quota-chart"`, `id="page-buttons" class="page-buttons admin-only"`, `id="user-usage"`, `id="usage-filter-panel" class="usage-filter-panel admin-only"`, `id="refresh" class="admin-only"`, `id="editor-quota"`, `id="billing-ledger"`, `id="key-management" class="user-management"`, `id="reset-all-billing"`, `id="key-rows" class="user-card-grid"`, `class="surface price-panel price-layout"`, `src="./ui-config.js"`, `type="module" src="./app/main.js"`, `href="./styles/base.css"`, `href="./styles/keys.css"`, `href="./styles/usage.css"`, `href="./styles/pricing.css"`} {
|
||||
if !strings.Contains(page, feature) {
|
||||
t.Fatalf("UI does not contain HTML feature %q", feature)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<base href="/v0/resource/plugins/billing/">
|
||||
<title>CPA</title>
|
||||
<link rel="stylesheet" href="./styles/base.css">
|
||||
<link rel="stylesheet" href="./styles/layout.css">
|
||||
|
||||
@@ -22,6 +22,9 @@ func NewServer(input Input) http.Handler {
|
||||
mux.HandleFunc("GET /ui-config.js", asset("text/javascript; charset=utf-8", []byte(`window.BILLING_UI_CONFIG = Object.freeze({managementBase:"/v0/management/plugins/billing",readOnlyBase:"/v0/resource/plugins/billing/ui",managementKey:"demo",lockManagementKey:true,hideManagementKey:true,demoPerspectives:true});`)))
|
||||
mux.HandleFunc("GET /styles/{name}", embeddedAsset("styles/"))
|
||||
mux.HandleFunc("GET /app/{path...}", embeddedAsset("app/"))
|
||||
mux.HandleFunc("GET /v0/resource/plugins/billing/ui-config.js", asset("text/javascript; charset=utf-8", []byte(`window.BILLING_UI_CONFIG = Object.freeze({managementBase:"/v0/management/plugins/billing",readOnlyBase:"/v0/resource/plugins/billing/ui",managementKey:"demo",lockManagementKey:true,hideManagementKey:true,demoPerspectives:true});`)))
|
||||
mux.HandleFunc("GET /v0/resource/plugins/billing/styles/{name}", embeddedAsset("styles/"))
|
||||
mux.HandleFunc("GET /v0/resource/plugins/billing/app/{path...}", embeddedAsset("app/"))
|
||||
mux.Handle(managementBase+"/", input)
|
||||
mux.Handle(resourceUI, input)
|
||||
return mux
|
||||
|
||||
@@ -13,7 +13,7 @@ func TestServerServesSplitUIAndFakeInput(t *testing.T) {
|
||||
server := httptest.NewServer(NewServer(NewFakeInput()))
|
||||
defer server.Close()
|
||||
|
||||
for _, path := range []string{"/ui", "/ui-config.js", "/styles/base.css", "/styles/keys.css", "/styles/usage.css", "/styles/pricing.css", "/app/main.js", "/app/core/runtime.js", "/app/features/keys.js", "/app/features/usage.js", "/app/features/pricing.js"} {
|
||||
for _, path := range []string{"/ui", "/ui-config.js", "/styles/base.css", "/styles/keys.css", "/styles/usage.css", "/styles/pricing.css", "/app/main.js", "/app/core/runtime.js", "/app/features/keys.js", "/app/features/usage.js", "/app/features/pricing.js", "/v0/resource/plugins/billing/ui-config.js", "/v0/resource/plugins/billing/styles/base.css", "/v0/resource/plugins/billing/app/main.js"} {
|
||||
response, err := http.Get(server.URL + path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user