Skip to content
On this page

Description

Use Nest.

Configuration

Create a .env file in the root directory, with the following contents:

yaml
# Database Config
DB_TYPE=mysql
DB_HOST=
DB_PORT=3306
DB_NAME=
DB_USER=
DB_PASS=

# Mailer Config
MAIL_HOST=smtp.qq.com
MAIL_PORT=465
MAIL_SSL=1
MAIL_USER=
MAIL_PASS=

# Telegram Bot
TG_TOKEN=
# 如果設置了 Domain,則使用 webhook 方式「必須使用 SSL」,否則使用 polling 方式
TG_WEBHOOK_DOMAIN=
TG_WEBHOOK_PATH=/tg-webhook
TG_WEBHOOK_PORT=443

configuration for database can be found in db/README.md

configuration for yeastar can be found in star/README.md

Project setup

bash
npm install

SQL Migration (慎用!!!建議直接在数据库中更改结构,避免使用迁移脚本更改数据库结构及導致字段數據丟失!)

开发时(慎用!!!)

npm run migration:generate src/migrations/CreateUserTable

生产部署(Docker/CI/CD 常用)(慎用!!!)

npm run build
npm run migration:run:prod
npm run start:prod

Generation commands

bash
# generate module
nest g module <module-name>

# generate controller
nest g controller <controller-name>

# generate service
nest g service <service-name>

# generate guard
nest g guard <guard-name>

Compile and run the project

bash
# development
npm run start

# watch mode
npm run start:dev

# production mode
npm run start:prod

Run tests

bash
# unit tests
npm run test

# e2e tests
npm run test:e2e

# test coverage
npm run test:cov

Deployment (Docker)

bash
# build and run docker containers
docker compose up --build -d

# run docker containers without recreating them
docker compose up -d --no-recreate

Frontend setup or update

Just place the frontend files in public folder

No need to restart the docker container. It will automatically serve the files.

Backend update

  1. if update package.json or Dockerfile, rebuild the container
bash
# rebuild
npm run build

# restart container
docker compose restart
  1. if only update dist, restart the container

Docker actions

bash
# attach to container
docker exec -it tps-server bash

# build and start container
docker compose up

# stop and remove container
docker compose down

# start
docker compose start

# restart
docker compose restart

# stop
docker compose stop

Pack (TAR)

./tar.sh

Extract (TAR)

先創建文件夾,再解壓縮檔案

tar -zxvf tps-server-xxxxxx_xxxxxx.tar.gz

Released under the MIT License.