开源项目 vpr-materials
使用教程
1. 项目的目录结构及介绍
vpr-materials/
├── 02-hello-vapor/
│ └── projects/
│ └── final/
│ └── HelloVapor
├── 05-persisting-models/
│ └── projects/
│ └── final/
│ └── TILApp
├── 06-configuring-database/
│ └── projects/
├── 07-crud-database-operations/
│ └── projects/
├── 08-basic-controllers/
│ └── projects/
├── 09-parent-child-relationships/
│ └── projects/
├── 10-sibling-relationships/
│ └── projects/
├── 34-deploying-with-aws/
│ └── projects/
│ └── starter/
│ └── TILApp
├── 35-production-concerns/
│ └── projects/
├── 36-microservices-redis/
│ └── projects/
├── 37-microservices-part2/
│ └── projects/
├── scripts/
├── .gitignore
├── LICENCE
├── README.md
目录结构介绍
02-hello-vapor/
: 包含基本的 Vapor 项目示例。05-persisting-models/
: 包含持久化模型的项目示例。06-configuring-database/
: 包含数据库配置的项目示例。07-crud-database-operations/
: 包含数据库 CRUD 操作的项目示例。08-basic-controllers/
: 包含基本控制器的项目示例。09-parent-child-relationships/
: 包含父子关系的项目示例。10-sibling-relationships/
: 包含兄弟关系的项目示例。34-deploying-with-aws/
: 包含部署到 AWS 的项目示例。35-production-concerns/
: 包含生产环境关注点的项目示例。36-microservices-redis/
: 包含微服务和 Redis 的项目示例。37-microservices-part2/
: 包含微服务第二部分的项目示例。scripts/
: 包含一些脚本文件。.gitignore
: Git 忽略文件。LICENCE
: 项目许可证。README.md
: 项目说明文件。
2. 项目的启动文件介绍
在 02-hello-vapor/projects/final/HelloVapor
目录下,启动文件通常是 Run
或 main.swift
。这个文件负责启动 Vapor 服务器。
import Vapor
var env = try Environment.detect()
try LoggingSystem.bootstrap(from: &env)
let app = Application(env)
defer { app.shutdown() }
try configure(app)
try app.run()
3. 项目的配置文件介绍
在 02-hello-vapor/projects/final/HelloVapor
目录下,配置文件通常是 configure.swift
。这个文件负责配置 Vapor 应用的各种设置,如路由、中间件、数据库连接等。
import Vapor
public func configure(_ app: Application) throws {
// 配置路由
try routes(app)
// 配置中间件
app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
// 配置数据库
app.databases.use(.sqlite(.file("db.sqlite")), as: .sqlite)
// 其他配置
// ...
}
以上是 vpr-materials
项目的基本使用教程,涵盖了项目的目录结构、启动文件和配置文件的介绍。希望这些信息能帮助你更好地理解和使用该项目。