2024-08-27 10:10:05 +08:00

135 lines
4.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# *coder station* 前台系统笔记
## 准备工作
1. **启动服务器**
首先从课件资料拿到服务器的项目目录coderstation-server(express+mongo),进入项目根目录,安装依赖:
```js
npm i
```
启动服务器:
```js
npm start
```
如果看到控制台如下的输出:
```js
服务器端已启动监听 7001 端口...
coderstation 数据库已经连接...
```
说明服务器已经启动成功。
2. **数据恢复**
在课件资料中你还能看到提前准备好了一些数据coderstationData接下来可以将数据进行一个恢复。
首先需要你安装 *Mongodb**https://www.mongodb.com/*
![image-20221109142847200](https://xiejie-typora.oss-cn-chengdu.aliyuncs.com/2022-11-09-062847.png)
接下来下载 mongodb
<img src="https://xiejie-typora.oss-cn-chengdu.aliyuncs.com/2022-11-09-062943.png" alt="image-20221109142943156" style="zoom:50%;" />
*Mac* 系统建议放置到 /usr/local/mongodb
<img src="https://xiejie-typora.oss-cn-chengdu.aliyuncs.com/2022-11-09-063106.png" alt="image-20221109143105682" style="zoom:50%;" />
要启动 mongodb需要 bin 目录下面的 mongod
后期可能会用到很多其他的可执行文件
<img src="https://xiejie-typora.oss-cn-chengdu.aliyuncs.com/2022-11-09-063207.png" alt="image-20221109143207171" style="zoom:50%;" />
新版本的 mongodb有一个特点就是 bin 目录下面的可执行文件大大减少,如果想要补全,需要自己去官网下载,下载下来是一个压缩包,解压就会得到一堆可执行文件,放入到 *Mongodb* 安装目录的 *bin* 目录下面
![image-20221109143317367](https://xiejie-typora.oss-cn-chengdu.aliyuncs.com/2022-11-09-063317.png)
启动 *Mongodb*,使用 *Mongod* 可执行文件
```js
./mongod -f 配置文件地址
例如
./mongod -f /usr/local/mongodb/mongodb.conf
```
<img src="https://xiejie-typora.oss-cn-chengdu.aliyuncs.com/2022-11-09-063605.png" alt="image-20221109143605101" style="zoom:50%;" />
配置文件的内容如下:
```js
systemLog:
destination: file # 日志输出方式file/syslog,如果是file需指定path默认是输出到标准输出流中
path: /usr/local/mongodb/mongod.log # 日志路径
logAppend: true # 启动时日志追加在已有日志文件内还是备份旧日志后创建新文件记录日志, 默认false
net:
port: 27017 # 监听端口默认27017
bindIp: 127.0.0.1 # 绑定监听的ip设置为127.0.0.1只会监听本机
maxIncomingConnections: 65536 # 最大连接数可接受的连接数还受限于操作系统配置的最大连接数
wireObjectCheck: true # 校验客户端的请求防止错误的或无效BSON插入,多层文档嵌套的对象会有轻微性能影响,默认true
processManagement:
fork: true # 后台运行
security:
authorization: disabled # enabled/disabled # 开启客户端认证
storage:
dbPath: /usr/local/mongodb/data # 数据库地址
```
> 注意:*Windows* 下面自带配置文件,后缀为 cfg然后还有就是 *windows* 下面的配置文件的格式会有一些区别
建议安装一个数据库可视化工具,这个自由选择:
- *robo3t*
- *stduio3t*:基础功能是免费的,*https://studio3t.com/*
- *compass*mongo 官方推出的可视化工具
- *navicat*
关于数据的恢复,这边需要使用到一个可执行命令,*mongorestore*,还需要保证 *mongodb* 的数据库服务器是启动起来的
<img src="https://xiejie-typora.oss-cn-chengdu.aliyuncs.com/2022-11-09-064349.png" alt="image-20221109144349195" style="zoom:50%;" />
```js
mongorestore -h dbhost -d dbname --dir dbdirectory
例如
./mongorestore -h localhost:27017 -d coderstation2 --dir /Users/jie/Desktop/coderstationData
```
如果你在恢复数据的时候,名字取了其他名字,服务器那边也需要修改成对应的名字:
<img src="https://xiejie-typora.oss-cn-chengdu.aliyuncs.com/2022-11-09-064932.png" alt="image-20221109144932400" style="zoom:50%;" />
3. **数据接口***https://yapi.duyiedu.com/project/387/interface/api*
4. **本次项目讲解约定**
- 这一次项目不会像个人博客,把所有的功能就讲解,只会讲解核心的功能,重复的代码模块大家自己完成
- 上课的时候不会带着写 *CSS*,涉及到 *CSS* 的时候会直接使用成品里面的 *CSS*
- 关于 *JSX* 部分,只会挑一些重要的来讲的,有一些 *JSX* 会直接从成品里面拿过来