2022-02-20 11:51:55 +00:00
|
|
|
|
# think
|
|
|
|
|
|
|
|
|
|
## 简介
|
|
|
|
|
|
|
|
|
|
Think 是一款开源知识管理工具。通过独立的知识库空间,结构化地组织在线协作文档,实现知识的积累与沉淀,促进知识的复用与流通。同时支持多人协作文档。使用的技术如下:
|
|
|
|
|
|
|
|
|
|
- `MySQL`:数据存储
|
|
|
|
|
- `next.js`:前端页面框架
|
|
|
|
|
- `nest.js`:服务端框架
|
|
|
|
|
- `AliyunOSS`:对象存储
|
|
|
|
|
- `tiptap`:编辑器及文档协作
|
|
|
|
|
|
2022-04-11 14:13:56 +00:00
|
|
|
|
可访问[云策文档帮助中心](https://think.codingit.cn/share/wiki/eb520cdf-aa4b-4af2-ae4a-7140e21403ab),查看更多功能文档。
|
2022-02-20 11:51:55 +00:00
|
|
|
|
|
|
|
|
|
## 链接
|
|
|
|
|
|
2022-04-11 14:13:56 +00:00
|
|
|
|
[云策文档](https://think.codingit.cn)已经部署上线,可前往注册使用。
|
2022-02-20 11:51:55 +00:00
|
|
|
|
|
2022-02-20 12:11:01 +00:00
|
|
|
|
## 预览
|
|
|
|
|
|
|
|
|
|
![首页](http://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-20/YN67GM4VQMBTZFZ88TYOZX/image.png)
|
|
|
|
|
![知识库](http://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-20/YN67GM4VQMBTZFZ88TYP8X/image.png)
|
|
|
|
|
![新建文档](http://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-20/YN67GM4VQMBTZFZ88TYPQX/image.png)
|
|
|
|
|
![编辑器](http://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-20/YN67GM4VQMBTZFZ88TYPZX/image.png)
|
|
|
|
|
![协作](http://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-20/YN67GM4VQMBTZFZ88TYQ8X/image.png)
|
|
|
|
|
![收藏](http://wipi.oss-cn-shanghai.aliyuncs.com/2022-02-20/YN67GM4VQMBTZFZ88TYPHX/image.png)
|
|
|
|
|
|
2022-02-20 11:51:55 +00:00
|
|
|
|
## 项目运行
|
|
|
|
|
|
|
|
|
|
本项目依赖 pnpm 使用 monorepo 形式进行代码组织,分包如下:
|
|
|
|
|
|
2022-03-30 06:38:17 +00:00
|
|
|
|
- `@think/config`: 客户端、服务端、OSS、MYSQL、Redis 等配置管理
|
|
|
|
|
- `@think/domains`:领域模型数据定义
|
|
|
|
|
- `@think/constants`:常量配置
|
2022-02-20 11:51:55 +00:00
|
|
|
|
- `@think/server`:服务端
|
|
|
|
|
- `@think/client`:客户端
|
|
|
|
|
|
|
|
|
|
### pnpm
|
|
|
|
|
|
|
|
|
|
项目依赖 pnpm,请安装后运行(`npm i -g pnpm`)。
|
|
|
|
|
|
|
|
|
|
### 数据库
|
|
|
|
|
|
|
|
|
|
首先安装 `MySQL`,推荐使用 docker 进行安装。
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
docker image pull mysql:5.7
|
2022-03-11 10:19:16 +00:00
|
|
|
|
# m1 的 mac 可以用:docker image pull --platform linux/x86_64 mysql:5.7
|
2022-02-20 11:51:55 +00:00
|
|
|
|
docker run -d --restart=always --name think -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root mysql:5.7
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
然后在 `MySQL` 中创建数据库。
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
docker container exec -it think bash;
|
|
|
|
|
mysql -u root -p;
|
|
|
|
|
CREATE DATABASE `think` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
|
|
|
```
|
|
|
|
|
|
2022-03-29 14:23:41 +00:00
|
|
|
|
#### 可选:Redis
|
|
|
|
|
|
2022-05-21 06:56:50 +00:00
|
|
|
|
如果需要文档版本服务,请在根目录 `yaml` 配置中进行 `db.redis` 的配置。
|
2022-03-30 04:25:08 +00:00
|
|
|
|
|
2022-03-29 14:23:41 +00:00
|
|
|
|
```
|
|
|
|
|
docker pull redis:latest
|
|
|
|
|
docker run --name think-redis -p 6379:6379 -d redis --appendonly yes --requirepass "root"
|
|
|
|
|
```
|
|
|
|
|
|
2022-02-20 11:51:55 +00:00
|
|
|
|
### 本地运行
|
|
|
|
|
|
|
|
|
|
首先,clone 项目。
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
git clone --depth=1 https://github.com/fantasticit/think.git your-project-name
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
然后,安装项目依赖。
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
pnpm install
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
- 启动项目
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
pnpm run dev
|
|
|
|
|
```
|
|
|
|
|
|
2022-05-21 14:11:13 +00:00
|
|
|
|
- 前台页面地址:`http://localhost:5001`。
|
|
|
|
|
- 服务接口地址:`http://localhost:5002`。
|
|
|
|
|
- 协作接口地址:`http://localhost:5003`。
|
2022-02-20 11:51:55 +00:00
|
|
|
|
|
2022-05-21 14:38:26 +00:00
|
|
|
|
如需修改配置,可在 `config/dev.yaml` 中进行配置。
|
2022-02-20 11:51:55 +00:00
|
|
|
|
|
|
|
|
|
### 配置文件
|
|
|
|
|
|
2022-05-21 14:38:26 +00:00
|
|
|
|
默认加载 `config/dev.yaml` 中的配置(生产环境使用 `config/prod.yaml` )。
|
2022-02-20 11:51:55 +00:00
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
# 开发环境配置
|
2022-05-21 06:56:50 +00:00
|
|
|
|
# 开发环境配置
|
|
|
|
|
client:
|
|
|
|
|
port: 5001
|
|
|
|
|
assetPrefix: '/'
|
|
|
|
|
apiUrl: 'http://localhost:5002/api'
|
|
|
|
|
collaborationUrl: 'ws://localhost:5003'
|
2022-05-22 02:33:08 +00:00
|
|
|
|
# 以下为页面 meta 配置
|
|
|
|
|
seoAppName: '云策文档'
|
|
|
|
|
seoDescription: '云策文档是一款开源知识管理工具。通过独立的知识库空间,结构化地组织在线协作文档,实现知识的积累与沉淀,促进知识的复用与流通。'
|
|
|
|
|
seoKeywords: '云策文档,协作,文档,前端面试题,fantasticit,https://github.com/fantasticit/think'
|
|
|
|
|
# 预先连接的来源,空格分割(比如图片存储服务器)
|
|
|
|
|
dnsPrefetch: '//wipi.oss-cn-shanghai.aliyuncs.com'
|
2022-05-21 06:56:50 +00:00
|
|
|
|
|
2022-02-20 11:51:55 +00:00
|
|
|
|
server:
|
2022-03-12 02:31:03 +00:00
|
|
|
|
prefix: '/api'
|
2022-05-21 06:56:50 +00:00
|
|
|
|
port: 5002
|
2022-02-20 11:51:55 +00:00
|
|
|
|
collaborationPort: 5003
|
2022-05-20 10:38:07 +00:00
|
|
|
|
maxDocumentVersion: 20 # 最大版本记录数
|
2022-05-21 06:56:50 +00:00
|
|
|
|
logRetainDays: 3 # 日志保留天数,比如只保留近三天日志
|
2022-02-20 11:51:55 +00:00
|
|
|
|
|
|
|
|
|
# 数据库配置
|
|
|
|
|
db:
|
|
|
|
|
mysql:
|
2022-03-12 02:31:03 +00:00
|
|
|
|
host: '127.0.0.1'
|
|
|
|
|
username: 'root'
|
|
|
|
|
password: 'root'
|
|
|
|
|
database: 'think'
|
2022-02-20 11:51:55 +00:00
|
|
|
|
port: 3306
|
2022-03-12 02:31:03 +00:00
|
|
|
|
charset: 'utf8mb4'
|
|
|
|
|
timezone: '+08:00'
|
2022-02-20 11:51:55 +00:00
|
|
|
|
synchronize: true
|
2022-03-30 06:38:17 +00:00
|
|
|
|
redis:
|
|
|
|
|
host: '127.0.0.1'
|
|
|
|
|
port: '6379'
|
|
|
|
|
password: 'root'
|
2022-02-20 11:51:55 +00:00
|
|
|
|
|
|
|
|
|
# oss 文件存储服务
|
|
|
|
|
oss:
|
|
|
|
|
aliyun:
|
2022-03-12 02:31:03 +00:00
|
|
|
|
accessKeyId: ''
|
|
|
|
|
accessKeySecret: ''
|
|
|
|
|
bucket: ''
|
2022-02-20 11:51:55 +00:00
|
|
|
|
https: true
|
2022-03-12 02:31:03 +00:00
|
|
|
|
region: ''
|
2022-02-20 11:51:55 +00:00
|
|
|
|
|
|
|
|
|
# jwt 配置
|
|
|
|
|
jwt:
|
2022-03-12 02:31:03 +00:00
|
|
|
|
secretkey: 'zA_Think+KNOWLEDGE+WIKI+DOCUMENTS@2022'
|
|
|
|
|
expiresIn: '6h'
|
2022-02-20 11:51:55 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 项目部署
|
|
|
|
|
|
|
|
|
|
生产环境部署的脚本如下:
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
|
|
|
|
node -v
|
|
|
|
|
npm -v
|
|
|
|
|
|
|
|
|
|
npm config set registry http://registry.npmjs.org
|
|
|
|
|
|
|
|
|
|
npm i -g pm2 @nestjs/cli pnpm
|
|
|
|
|
|
|
|
|
|
pnpm install
|
|
|
|
|
pnpm run build
|
|
|
|
|
pnpm run pm2
|
|
|
|
|
|
|
|
|
|
pm2 startup
|
|
|
|
|
pm2 save
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### nginx 配置
|
|
|
|
|
|
|
|
|
|
采用反向代理进行 `nginx` 配置,**同时设置 `proxy_set_header X-Real-IP $remote_addr;` 以便服务端获取到真实 ip 地址**。
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
upstream wipi_client {
|
|
|
|
|
server 127.0.0.1:3000;
|
|
|
|
|
keepalive 64;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# http -> https 重定向
|
|
|
|
|
server {
|
|
|
|
|
listen 80;
|
|
|
|
|
server_name 域名;
|
|
|
|
|
rewrite ^(.*)$ https://$host$1 permanent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
server {
|
|
|
|
|
listen 443 ssl;
|
|
|
|
|
server_name 域名;
|
|
|
|
|
ssl_certificate 证书存放路径;
|
|
|
|
|
ssl_certificate_key 证书存放路径;
|
|
|
|
|
|
|
|
|
|
location / {
|
|
|
|
|
proxy_http_version 1.1;
|
|
|
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
|
|
|
proxy_set_header Connection "upgrade";
|
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
|
proxy_set_header X-Nginx-Proxy true;
|
|
|
|
|
proxy_cache_bypass $http_upgrade;
|
|
|
|
|
proxy_pass http://wipi_client; #反向代理
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
|
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2022-03-24 06:07:25 +00:00
|
|
|
|
## 自动化部署
|
|
|
|
|
|
|
|
|
|
> 思路:在服务器部署 webhook,然后在 github setting 中配置相应钩子,实现自动化部署
|
|
|
|
|
|
|
|
|
|
参考:[webhook](https://github.com/adnanh/webhook/blob/master/docs/Hook-Examples.md#incoming-github-webhook)
|
|
|
|
|
|
2022-02-20 11:51:55 +00:00
|
|
|
|
## 资料
|
|
|
|
|
|
|
|
|
|
- next.js 源码:https://github.com/vercel/next.js
|
|
|
|
|
- next.js 文档:https://nextjs.org/
|
|
|
|
|
- nest.js 源码:https://github.com/nestjs/nest
|
|
|
|
|
- nest.js 文档:https://nestjs.com/
|