Truthy CMS(NestJS Headless API)项目教程

Truthy CMS(NestJS Headless API)项目教程

truthy Open source headless CMS API written using NestJS, that has pre built modules like User Management, Role Management, Permission Management, Email Module, Account Settings, OTP, Throttling, RBAC support, Localization, and many more. truthy 项目地址: https://gitcode.com/gh_mirrors/tr/truthy

1. 项目目录结构及介绍

Truthy CMS 是一个基于 NestJS 的 Headless API 项目,其目录结构如下:

truthy/
├── config/                                  * 包含所有配置文件
│   ├── default.yml                         * 默认配置文件
│   ├── development.yml                     * 开发环境配置文件
│   ├── production.yml                      * 生产环境配置文件
│   └── test.yml                            * 测试环境配置文件
├── coverage/                               * 运行 `yarn coverage` 命令后的覆盖率报告
├── dist/                                   * 经过 `yarn build` 编译后的生产环境代码
├── images/                                 * 存储上传的资料图片,该文件夹被 git 忽略
├── src/
│   ├── common/                             * 公共帮助函数、DTO、实体、异常、装饰器等
│   ├── config/                             * 配置变量文件
│   ├── database/                           * 数据库文件夹,包括迁移和种子
│   └── <module>/                           * 特定模块的所有文件
│       ├── dto/
│       ├── entity/
│       ├── pipes/
│       ├── serializer/
│       ├── <module>.controller.ts          * 模块控制器文件
│       ├── <module>.module.ts              * 模块根文件
│       ├── <module>.service.ts             * 模块服务文件
│       ├── <module>.service.spec.ts        * 服务测试文件
│       ├── <module>.repository.ts          * 模块仓库文件
│       └── <module>.repository.spec.ts     * 仓库测试文件
├── .gitignore
├── .dockerignore
├── .env.example
├── .eslintrc.js
├── .husky/
├── .lintstagedrc.json
├── .prettierrc
├── .travis.yml
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── Dockerfile
├── Dockerfile.dev
├── LICENSE
├── PULL_REQUEST_TEMPLATE.md
├── Procfile
├── README.md
├── docker-compose-test.yml
├── docker-compose.yml
├── index.js
├── nest-cli.json
├── package.json
├── tsconfig.build.json
├── tsconfig.json
└── yarn.lock

2. 项目的启动文件介绍

项目的启动文件是 src/index.ts,该文件的主要作用是创建 NestJS 应用实例并监听指定的端口。以下是一个简化的启动文件示例:

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  await app.listen(3000);
}
bootstrap();

在这个文件中,我们导入了 NestFactory 来创建 NestJS 应用实例,并导入了 AppModule 作为应用的根模块。然后,我们调用 bootstrap 函数来启动应用,并监听默认的端口 3000

3. 项目的配置文件介绍

项目的配置文件位于 config 文件夹中,根据不同的环境(开发、生产、测试)有不同的配置文件。以下是一个配置文件的示例:

# config/default.yml
server:
  port: 3000
database:
  host: localhost
  port: 5432
  username: postgres
  password: root
  database: truthy
redis:
  port: 6379
  host: localhost

default.yml 文件中,我们定义了服务器的端口、数据库的连接信息以及 Redis 的连接信息。这些配置项可以根据实际环境进行调整,例如在生产环境中,你可能需要更改数据库的主机名、端口号、用户名和密码。

在运行项目时,环境变量会覆盖配置文件中的对应设置,这使得在不同环境中灵活配置项目成为可能。

truthy Open source headless CMS API written using NestJS, that has pre built modules like User Management, Role Management, Permission Management, Email Module, Account Settings, OTP, Throttling, RBAC support, Localization, and many more. truthy 项目地址: https://gitcode.com/gh_mirrors/tr/truthy

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

时飞城Herdsman

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值