Skip to content

Commit 30dd792

Browse files
insistencegitee-org
authored andcommitted
!18 Dash-FastAPI-Admin v1.2.0
Merge pull request !18 from insistence/develop
2 parents 30e44aa + 0c327a4 commit 30dd792

File tree

20 files changed

+453
-66
lines changed

20 files changed

+453
-66
lines changed

README.md

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<p align="center">
22
<img alt="logo" src="https://oscimg.oschina.net/oscnet/up-d3d0a9303e11d522a06cd263f3079027715.png">
33
</p>
4-
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">Dash-FastAPI-Admin v1.1.0</h1>
4+
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">Dash-FastAPI-Admin v1.2.0</h1>
55
<h4 align="center">基于Dash+FastAPI前后端分离的纯Python快速开发框架</h4>
66
<p align="center">
77
<a href="https://gitee.com/insistence2022/dash-fastapi-admin/stargazers"><img src="https://gitee.com/insistence2022/dash-fastapi-admin/badge/star.svg?theme=dark"></a>
88
<a href="https://github.com/insistence/Dash-FastAPI-Admin"><img src="https://img.shields.io/github/stars/insistence/Dash-FastAPI-Admin?style=social"></a>
9-
<a href="https://gitee.com/insistence2022/dash-fastapi-admin"><img src="https://img.shields.io/badge/DashFastAPIAdmin-v1.1.0-brightgreen.svg"></a>
9+
<a href="https://gitee.com/insistence2022/dash-fastapi-admin"><img src="https://img.shields.io/badge/DashFastAPIAdmin-v1.2.0-brightgreen.svg"></a>
1010
<a href="https://gitee.com/insistence2022/dash-fastapi-admin/blob/master/LICENSE"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"></a>
1111
<img src="https://img.shields.io/badge/python-3.8 | 3.9-blue">
1212
<img src="https://img.shields.io/badge/MySQL-≥5.7-blue">
@@ -97,7 +97,7 @@ Dash-FastAPI-Admin是一套全部开源的快速开发平台,毫无保留给
9797
- *密码:admin123*
9898
- 演示地址:<a href="https://dfadmin.insistence.tech">dfadmin管理系统<a>
9999

100-
## 项目运行相关
100+
## 项目开发及发布
101101

102102
```bash
103103
# 克隆项目
@@ -110,30 +110,94 @@ cd dash-fastapi-admin
110110
pip3 install -r requirements.txt
111111
```
112112

113-
### 前端
113+
### 开发
114+
115+
#### 前端
116+
```bash
117+
# 进入前端目录
118+
cd dash-fastapi-frontend
119+
120+
# 配置应用信息
121+
在.env.dev文件中配置应用开发模式的相关信息
122+
123+
# 运行前端
124+
python3 app.py --env=dev
125+
```
126+
127+
#### 后端
128+
```bash
129+
# 进入后端目录
130+
cd dash-fastapi-backend
131+
132+
# 配置环境
133+
1.在.env.dev文件中配置开发模式的数据库环境
134+
2.在.env.dev文件中配置开发模式的redis环境
135+
136+
# 运行sql文件
137+
1.新建数据库dash-fastapi(默认,可修改)
138+
2.使用命令或数据库连接工具运行sql文件夹下的dash-fastapi.sql
139+
140+
# 运行后端
141+
python3 app.py --env=dev
142+
```
143+
144+
### 发布
145+
146+
本应用发布建议使用nginx部署,nginx代理配置参考如下:
147+
148+
```bash
149+
server {
150+
location / {
151+
proxy_set_header Host $http_host;
152+
proxy_set_header X-Real-IP $remote_addr;
153+
proxy_set_header REMOTE-HOST $remote_addr;
154+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
155+
proxy_pass http://127.0.0.1:8088/;
156+
}
157+
158+
location /prod-api {
159+
proxy_set_header Host $http_host;
160+
proxy_set_header X-Real-IP $remote_addr;
161+
proxy_set_header REMOTE-HOST $remote_addr;
162+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
163+
proxy_pass http://127.0.0.1:9099/;
164+
rewrite ^/prod-api/(.*)$ /$1 break;
165+
}
166+
167+
error_page 500 502 503 504 /50x.html;
168+
location = /50x.html {
169+
root html;
170+
}
171+
}
172+
```
173+
174+
#### 前端
114175
```bash
115176
# 进入前端目录
116177
cd dash-fastapi-frontend
117178

179+
# 配置应用信息
180+
在.env.prod文件中配置应用发布的相关信息,注意:APP_BASE_URL需要配置为nginx代理的地址,例如上面的nginx代理监听的是8000端口,则APP_BASE_URL需要配置为http://127.0.0.1:8000
181+
118182
# 运行前端
119-
python3 wsgi.py
183+
python3 wsgi.py --env=prod
120184
```
121185

122-
### 后端
186+
#### 后端
123187
```bash
124188
# 进入后端目录
125189
cd dash-fastapi-backend
126190

127191
# 配置环境
128-
1.在config/env.py的DataBaseConfig类中配置数据库环境
129-
2.在config/env.py的RedisConfig类中配置redis环境
192+
1.在.env.prod文件中配置生产模式的数据库环境
193+
2.在.env.prod文件中配置生产模式的redis环境
130194

131195
# 运行sql文件
132196
1.新建数据库dash-fastapi(默认,可修改)
133197
2.使用命令或数据库连接工具运行sql文件夹下的dash-fastapi.sql
134198

135199
# 运行后端
136-
python3 app.py
200+
python3 app.py --env=prod
137201
```
138202

139203
### 访问

dash-fastapi-backend/.env.dev

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# -------- 应用配置 --------
2+
# 应用运行环境
3+
APP_ENV = 'dev'
4+
# 应用名称
5+
APP_NAME = 'Dash-FasAPI-Admin'
6+
# 应用代理路径
7+
APP_ROOT_PATH = ''
8+
# 应用主机
9+
APP_HOST = '0.0.0.0'
10+
# 应用端口
11+
APP_PORT = 9099
12+
# 应用版本
13+
APP_VERSION= '1.2.0'
14+
# 应用是否开启热重载
15+
APP_RELOAD = true
16+
17+
# -------- Jwt配置 --------
18+
# Jwt秘钥
19+
JWT_SECRET_KEY = 'b01c66dc2c58dc6a0aabfe2144256be36226de378bf87f72c0c795dda67f4d55'
20+
# Jwt算法
21+
JWT_ALGORITHM = 'HS256'
22+
# 令牌过期时间
23+
JWT_EXPIRE_MINUTES = 1440
24+
# redis中令牌过期时间
25+
JWT_REDIS_EXPIRE_MINUTES = 30
26+
27+
28+
# -------- 数据库配置 --------
29+
# 数据库主机
30+
DB_HOST = '127.0.0.1'
31+
# 数据库端口
32+
DB_PORT = 3306
33+
# 数据库用户名
34+
DB_USERNAME = 'root'
35+
# 数据库密码
36+
DB_PASSWORD = 'mysqlroot'
37+
# 数据库名称
38+
DB_DATABASE = 'dash-fastapi'
39+
40+
# -------- Redis配置 --------
41+
# Redis主机
42+
REDIS_HOST = '127.0.0.1'
43+
# Redis端口
44+
REDIS_PORT = 6379
45+
# Redis用户名
46+
REDIS_USERNAME = ''
47+
# Redis密码
48+
REDIS_PASSWORD = ''
49+
# Redis数据库
50+
REDIS_DATABASE = 2

dash-fastapi-backend/.env.prod

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# -------- 应用配置 --------
2+
# 应用运行环境
3+
APP_ENV = 'prod'
4+
# 应用名称
5+
APP_NAME = 'Dash-FasAPI'
6+
# 应用代理路径
7+
APP_ROOT_PATH = '/prod-api'
8+
# 应用主机
9+
APP_HOST = '0.0.0.0'
10+
# 应用端口
11+
APP_PORT = 9099
12+
# 应用版本
13+
APP_VERSION= '1.2.0'
14+
# 应用是否开启热重载
15+
APP_RELOAD = false
16+
17+
# -------- Jwt配置 --------
18+
# Jwt秘钥
19+
JWT_SECRET_KEY = 'b01c66dc2c58dc6a0aabfe2144256be36226de378bf87f72c0c795dda67f4d55'
20+
# Jwt算法
21+
JWT_ALGORITHM = 'HS256'
22+
# 令牌过期时间
23+
JWT_EXPIRE_MINUTES = 1440
24+
# redis中令牌过期时间
25+
JWT_REDIS_EXPIRE_MINUTES = 30
26+
27+
28+
# -------- 数据库配置 --------
29+
# 数据库主机
30+
DB_HOST = '127.0.0.1'
31+
# 数据库端口
32+
DB_PORT = 3306
33+
# 数据库用户名
34+
DB_USERNAME = 'root'
35+
# 数据库密码
36+
DB_PASSWORD = 'mysqlroot'
37+
# 数据库名称
38+
DB_DATABASE = 'dash-fastapi'
39+
40+
# -------- Redis配置 --------
41+
# Redis主机
42+
REDIS_HOST = '127.0.0.1'
43+
# Redis端口
44+
REDIS_PORT = 6379
45+
# Redis用户名
46+
REDIS_USERNAME = ''
47+
# Redis密码
48+
REDIS_PASSWORD = ''
49+
# Redis数据库
50+
REDIS_DATABASE = 2

dash-fastapi-backend/app.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from module_admin.controller.server_controller import serverController
1919
from module_admin.controller.cache_controller import cacheController
2020
from module_admin.controller.common_controller import commonController
21+
from config.env import AppConfig
2122
from config.get_redis import RedisUtil
2223
from config.get_db import init_create_table
2324
from config.get_scheduler import SchedulerUtil
@@ -26,9 +27,10 @@
2627
from utils.common_util import worship
2728

2829
app = FastAPI(
29-
title='Dash-FastAPI',
30-
description='Dash-FastAPI接口文档',
31-
version='1.0.0',
30+
title=AppConfig.app_name,
31+
description=f'{AppConfig.app_name}接口文档',
32+
version=AppConfig.app_version,
33+
root_path=AppConfig.app_root_path,
3234
)
3335

3436
# 前端页面url
@@ -49,14 +51,14 @@
4951

5052
@app.on_event("startup")
5153
async def startup_event():
52-
logger.info("Dash-FastAPI开始启动")
54+
logger.info(f"{AppConfig.app_name}开始启动")
5355
worship()
5456
await init_create_table()
5557
app.state.redis = await RedisUtil.create_redis_pool()
5658
await RedisUtil.init_sys_dict(app.state.redis)
5759
await RedisUtil.init_sys_config(app.state.redis)
5860
await SchedulerUtil.init_system_scheduler()
59-
logger.info("Dash-FastAPI启动成功")
61+
logger.info(f"{AppConfig.app_name}启动成功")
6062

6163

6264
@app.on_event("shutdown")
@@ -103,4 +105,9 @@ async def http_exception_handler(request: Request, exc: HTTPException):
103105
app.include_router(commonController, prefix="/common", tags=['通用模块'])
104106

105107
if __name__ == '__main__':
106-
uvicorn.run(app='app:app', host="0.0.0.0", port=9099, reload=True)
108+
uvicorn.run(
109+
app='app:app',
110+
host=AppConfig.app_host,
111+
port=AppConfig.app_port,
112+
reload=AppConfig.app_reload
113+
)

dash-fastapi-backend/config/database.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from urllib.parse import quote_plus
55
from config.env import DataBaseConfig
66

7-
SQLALCHEMY_DATABASE_URL = f"mysql+pymysql://{DataBaseConfig.USERNAME}:{quote_plus(DataBaseConfig.PASSWORD)}@" \
8-
f"{DataBaseConfig.HOST}:{DataBaseConfig.PORT}/{DataBaseConfig.DB}"
7+
SQLALCHEMY_DATABASE_URL = f"mysql+pymysql://{DataBaseConfig.db_username}:{quote_plus(DataBaseConfig.db_password)}@" \
8+
f"{DataBaseConfig.db_host}:{DataBaseConfig.db_port}/{DataBaseConfig.db_database}"
99

1010
engine = create_engine(
1111
SQLALCHEMY_DATABASE_URL, echo=True

0 commit comments

Comments
 (0)