feat(frontend): P2-A static hosting + API client + login/session integration (v0.3.1) - #78
Merged
Merged
Conversation
- 后端:router fallback_service(ServeDir::new("ui")) 静态托管(API 路由优先);新增 GET /api/me(id/email/name/role)
- ui/js/api.js 新增:api.get/post/patch 封装 + Bearer token(记住我 localStorage / 关闭失效 sessionStorage)+ 401 统一清 token 回登录页 + 非 2xx 抛 {status,message} + ?api= base 覆盖
- 登录页对接 POST /api/auth/login:成功存 token 拉会话(/api/me + /api/wallet 侧边栏余额);401 行内报错;登出清 token;刷新有 token 自动恢复会话
- 管理视图按 role 显隐(renderNav 过滤 + switchView/快捷键兜底);登录页文案更新(demo/admin 账号提示)
- 测试 61→63(静态托管返回 index.html / me 返回用户信息与 role)
13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Backend P2-A — frontend integration phase 1 (rant
2026-08-18T11:49:52.330450, "前端对接 P2-A — 静态托管 + API 客户端层 + 登录/会话对接"). Makes the UI prototype run against the real backend (v0.3.1):Router::fallback_service(ServeDir::new("ui"))(API routes take priority; tower-httpfsfeature already present).cargo run→ browsehttp://127.0.0.1:8080/opens the app directly.ui/js/api.js, new) —api.get/post/patchwith automaticAuthorization: Bearer <token>; token inlocalStorage(remember-me) vssessionStorage(session-only); unified 401 handling (clear token → back to login); non-2xx throws{status, message}from backenderror.message/error; base URL same-origin by default, overridable via?api=.app.js) —POST /api/auth/login→ save token →GET /api/me(new endpoint returning id/email/name/role) +GET /api/wallet(sidebar balance =available, failure → 0 + red toast); wrong password → inline field error; logout clears token; refresh with token auto-restores session.role=admin(renderNav filter + switchView/keyboard guards).Related Issue
Rant:
2026-08-18T11:49:52.330450(P2-A frontend integration)Tests
cargo fmt --check+cargo clippy --all-targets -- -D warningsclean;node --checkon new/modified JSGET /→ 200 text/html;/js/api.js→ 200; demo login → key;/api/me→{name: 阿零, role: user};/api/wallet→ real balance; wrong password → 401; admin login →role: admin; admin users 200 / demo 403; API routes take priority over staticChecklist
feat/frontend-p2a-serve-login)