Files
shrimp-server/examples/basic-admin
wc24 27a2348815 demo: 加 Vue 前端到 examples/basic-admin/web
为了端到端验证 Shrimp 框架,把 hand-admin 前端拷进 examples/basic-admin/web
作为临时演示用前端,@shrimp alias 直接指向同仓 src/,免构建。

修改要点:
- web/vite.config.ts: @shrimp 改成 ../../../src; proxy /admin-api 到 :3100
- web/tsconfig.json: 同步 @shrimp 路径; 删掉 hand-server-2 的 paths
- web/src/locales: 删掉 matter_*/zerobase 业务 key
- web/src/module: 删掉 matter_*/zerobase 业务 vue,只留 user/role/FieldRelativeTime
- examples/basic-admin/index.ts:
  - mount 到 /admin-api/* 而不是 /api/*
  - 加 /config /login /me 端点 (mock super-admin operator,固定 token)
  - DemoShrimp 子类覆盖 getMenuTree 用模块自身 label
  - MemoryShrimpCrud 的 getRelatedCrud 手动 wire 到 crudRegistry,
    populate 才能跑 (后续 70→90 改进项)

curl 已验证 /config /login /me /product/list 全通,tagIds_label 正确旁挂。
2026-05-23 15:28:10 +08:00
..

basic-admin demo

零外部依赖的 Shrimp demo,只用内存 CRUD,不依赖 MongoDB。

证明:Shrimp 的核心(模块注册 / RPC dispatch / 字段配置)在没有 mongoose、没有 JWT、没有用户表的情况下也能跑。

起服务

从 demo 目录起(本地链 shrimp-server):

cd examples/basic-admin
npm install
npm start

或者从仓库根目录直接 npm run demo(由根 package.json 提供)。

服务起在 http://localhost:3100。

试一下

# 列商品
curl -s -X POST http://localhost:3100/api/product/list \
  -H 'content-type: application/json' -d '[{}]' | jq

# 列标签
curl -s -X POST http://localhost:3100/api/tag/list \
  -H 'content-type: application/json' -d '[{}]' | jq

# 新增商品
curl -s -X POST http://localhost:3100/api/product/add \
  -H 'content-type: application/json' \
  -d '[{"code":"P003","name":"橙子","price":4,"tagIds":[]}]' | jq

# 改某个商品
curl -s -X POST http://localhost:3100/api/product/edit \
  -H 'content-type: application/json' -d '["1",{"price":99}]' | jq

# 删除商品
curl -s -X POST http://localhost:3100/api/product/delete \
  -H 'content-type: application/json' -d '["1"]' | jq

请求体永远是参数数组,按位置传给事件 handler。

这个 demo 暴露了哪些 70→90 的问题

  • Shrimp.ts:322 的 if ((dataSource as any).model) 让 MemoryShrimpCrud 不能注册到 crudRegistry,relation populate 自动联表对内存数据源不生效
  • 没有现成的 RPC mount helper — 这段 app.post("/api/*splat", ...) 应该是框架提供的,而不是 demo 里手写
  • 要登录 / 鉴权要么自己写,要么用 ShrimpServer 强吃 Mongo+JWT,中间没有"我只想要 RPC + 模块,自己接 auth"这条路径