Skip to content
T-130Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

8 Commits

Folders and files

Repository files navigation

Sprouts

一个轻量级个人博客系统,Rust 后端 + React 前端,单二进制部署。

English

技术栈

层 技术
后端 Rust / Axum / SQLite / JWT
前端 React 19 / TypeScript / Vite 8 / React Router 7
构建 Cargo build.rs 自动编译前端并嵌入二进制

快速开始

环境要求

  • Rust 1.85+
  • Node.js 20+

开发运行

# 1. 前端(可选,独立开发时)
cd sprouts-h5 && npm install && npm run dev

# 2. 后端(编译时自动构建前端并嵌入)
cargo run

启动后访问 http://127.0.0.1:3000。

默认管理员账号:admin / admin

生产构建

cargo build --release

产物 target/release/sprouts 是单二进制文件,部署时只需:

/opt/sprouts/
├── sprouts         # 二进制
├── config.toml     # 配置文件
└── db/             # SQLite 数据目录(自动创建)

项目结构

sprouts/
├── config.toml          # 后端配置(JWT、数据库路径、种子用户等)
├── build.rs             # 构建脚本:编译前端 → 嵌入静态资源
├── Cargo.toml
├── sprouts-h5/          # 前端项目(React + Vite)
│   ├── src/
│   │   ├── pages/       # 页面组件
│   │   ├── components/  # 公共组件
│   │   ├── hooks/       # 自定义 hooks
│   │   ├── api/         # 接口请求
│   │   └── types/       # 类型定义
│   ├── vite.config.ts
│   └── package.json
├── src/                 # 后端源码
│   ├── main.rs          # 入口:加载配置 → 启动服务
│   ├── server.rs        # Axum 路由、中间件、AppState
│   ├── config/          # 配置模块(TOML 解析 + 查找逻辑)
│   ├── auth/            # JWT 生成/验证 + 请求提取器
│   ├── db/              # SQLite 数据库层(表创建、CRUD)
│   └── handlers/        # 路由处理函数
├── db/                  # SQLite 数据文件目录
├── static/              # 构建产物(build.rs 自动生成,不提交 git)
└── target/              # Rust 编译产物(不提交 git)

配置文件

config.toml 按以下优先级查找:

  1. 环境变量 SPROUTS_CONFIG 指定的路径
  2. 二进制文件同目录下的 config.toml
  3. 当前工作目录下的 config.toml
[server]
host = "0.0.0.0"
port = 3000

[database]
path = "db/sprouts.db"

[auth]
jwt_secret = "your-secret-here"   # 生产环境务必修改
jwt_expiry_seconds = 86400

[seed]
admin_username = "admin"
admin_password = "admin"          # 生产环境务必修改
admin_nickname = "管理员"
admin_email = "admin@sprouts.local"
admin_role = "admin"
admin_salt = "your-salt-here"     # 生产环境务必修改

API 接口

方法 路径 说明 认证
POST /api/login 用户登录,返回 JWT 无
POST /api/users 创建用户 Admin
GET /api/articles 文章列表,支持 ?category=&q= 无
GET /api/articles/{id} 文章详情 无
GET /api/health 健康检查 无

认证方式:请求头 Authorization: Bearer <token>

前端路由

使用 HashRouter,路径格式为 /#/xxx:

路径 页面
/#/ 首页(文章列表)
/#/login 登录
/#/register 注册新用户(需管理员登录)
/#/article/:id 文章详情
/#/about 关于

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages