# fastweb **Repository Path**: papwuj/fastweb ## Basic Information - **Project Name**: fastweb - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-11-03 - **Last Updated**: 2025-11-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # FastWeb 一个基于 actix-web 的通用 Web 项目框架,采用 workspace 结构,包含多个可复用的库模块。 ## 项目结构 ``` fastweb/ ├── Cargo.toml # Workspace 配置 ├── fastweb-server/ # 主应用(Web服务器) │ └── src/main.rs ├── fastweb-common/ # 通用工具库 │ ├── src/ │ │ ├── lib.rs │ │ ├── utils.rs # 工具函数(时间戳、字符串、数字等) │ │ └── response.rs # 标准API响应结构 │ └── Cargo.toml ├── fastweb-config/ # 配置管理库 │ ├── src/ │ │ ├── lib.rs │ │ ├── loader.rs # 配置加载器 │ │ └── settings.rs # 配置结构定义 │ └── Cargo.toml ├── fastweb-middleware/ # 中间件库 │ ├── src/ │ │ ├── lib.rs │ │ ├── cors.rs # CORS中间件 │ │ ├── logger.rs # 请求日志中间件 │ │ └── auth.rs # 认证中间件 │ └── Cargo.toml ├── fastweb-db/ # 数据库操作库 │ ├── src/ │ │ ├── lib.rs │ │ ├── database_driver.rs # 数据库驱动 │ │ ├── db_initializer.rs # 数据库初始化 │ │ ├── db_query.rs # 数据库查询接口 │ │ └── pool.rs # 连接池管理 │ └── Cargo.toml ├── fastweb-cms/ # CMS核心功能库 │ ├── src/ │ │ ├── lib.rs │ │ ├── module.rs # 模块定义 │ │ └── cms/ # CMS功能实现 │ └── Cargo.toml └── fastweb-cms-frontend/ # CMS前端项目(React + Vite) ├── src/ # 前端源码 ├── public/ # 静态资源 ├── package.json # NPM配置 └── vite.config.js # Vite配置 ``` ## 模块说明 ### fastweb-common 提供通用的工具类和辅助函数: - **utils**: 时间戳工具、字符串工具、数字工具、分页参数 - **response**: 标准API响应结构(`ApiResponse`)和分页响应(`PageResponse`) ### fastweb-config 提供统一的配置管理: - 支持从文件和环境变量加载配置 - 支持多环境配置(开发、测试、生产) - 包含服务器配置、日志配置、数据库配置等 ### fastweb-middleware 提供常用的Web中间件: - **CORS**: 跨域资源共享配置 - **Logger**: 请求日志记录 - **Auth**: Bearer Token认证中间件 ### fastweb-server 主Web应用,集成所有模块,提供示例API接口。 ## 使用方法 ### 运行服务器 ```bash # 在项目根目录运行 cargo run --bin fastweb-server # 或者进入fastweb-server目录 cd fastweb-server cargo run ``` ### 测试API 服务器启动后,可以通过以下接口测试: - **健康检查**: `GET http://localhost:8080/health` - **获取用户列表**: `GET http://localhost:8080/api/users` - **获取单个用户**: `GET http://localhost:8080/api/users/{id}` - **创建用户**: `POST http://localhost:8080/api/users` ### 配置 创建 `config/default.toml` 文件来自定义配置: ```toml [server] host = "127.0.0.1" port = 8080 workers = 4 [log] level = "info" [database] url = "postgres://user:pass@localhost/dbname" pool_size = 10 ``` 也可以通过环境变量覆盖配置,变量名格式:`FASTWEB_SERVER_HOST`、`FASTWEB_SERVER_PORT` 等。 ## 开发 ### 添加新的库模块 1. 在根目录 `Cargo.toml` 的 `[workspace.members]` 中添加新模块 2. 创建新的模块目录和 `Cargo.toml` 3. 在需要的地方引用新模块 ### 依赖管理 所有公共依赖定义在根目录 `Cargo.toml` 的 `[workspace.dependencies]` 中,子项目通过 `workspace = true` 引用。 ## 技术栈 - **actix-web**: Web框架 - **tokio**: 异步运行时 - **serde**: 序列化/反序列化 - **config**: 配置管理 - **chrono**: 时间处理 - **thiserror**: 错误处理 - **log/env_logger**: 日志 ## License MIT