Skip to content

Commit 1ccd930

Browse files
committed
add server&frontend template
1 parent 236ee28 commit 1ccd930

File tree

155 files changed

+34645
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+34645
-5
lines changed

side_project/3-template.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
所有前端页面都已适配手机端,并且包含基本的组件,比如表单校验、toast提示、loading动效、图片拖拽上传等等。
66

7-
获取付费版模板代码:
7+
模板代码见本文末尾。
88

99
目录:
1010

@@ -92,7 +92,7 @@
9292

9393
1. 登录态
9494

95-
免费版没有登录后的展示逻辑,包括功能页面、充值页面、个人中心。免费版模板只能看到登录前的页面,且没有登录功能
95+
免费版没有登录后的展示逻辑,包括功能页面、充值页面、个人中心。免费版模板只能看到登录前的页面,且没有登录注册功能
9696

9797
2. 登录/注册页面
9898

@@ -106,6 +106,10 @@
106106

107107
因为没有登录后的逻辑,所以免费版也没有额度计算的逻辑
108108

109+
5. 生成记录
110+
111+
免费版不会记录用户的生成历史
112+
109113
## 付费版
110114

111115
付费版有着全面的功能,包括:
@@ -117,3 +121,11 @@
117121
- 功能主页面可使用(提供了去除背景、背景替换的功能,需要其他功能可以联系我)
118122
- 保存用户生成历史,图片上传到对象存储
119123
- 接入了stripe的收银台,点击支付可以跳转到收银台(支付回调通知需要自己接入)
124+
125+
# 模板代码
126+
127+
- 服务端模板代码免费版:[rpbg-server](./rpbg-server-free)
128+
129+
- 前端模板代码免费版:[web-starter-template-free](./web-starter-template-free)
130+
131+
- 获取付费版模板代码:

side_project/4-django-server.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 如何自定义模板服务端代码
22

3-
获取付费版模板代码:
3+
- 服务端模板代码免费版:[rpbg-server](./rpbg-server-free)
4+
- 获取付费版模板代码:
45

56
## 本地安装
67

side_project/5-nextjs-frontend.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 如何自定义模板前端代码
22

3-
获取付费版模板代码:
3+
- 前端模板代码免费版:[web-starter-template-free](./web-starter-template-free)
4+
- 获取付费版模板代码:
45

56
## 本地安装
67

side_project/6-deploy.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# 部署项目代码
2+
3+
- 服务端模板代码免费版:[rpbg-server](./rpbg-server-free)
4+
- 前端模板代码免费版:[web-starter-template-free](./web-starter-template-free)
5+
- 获取付费版模板代码:
6+
7+
## 服务端模板代码部署
8+
9+
### 前置准备
10+
首先,需要按照[自定义服务端代码](./4-django-server.md)中的[#项目配置]部分配置好需要的token。
11+
12+
其次,需要到阿里云租一个普通的ECS服务器(Ubuntu),并且开放服务器的http、https、ssh端口,也就是80、443、22端口;如果想要通过域名访问的话,需要申请好域名、备案通过,并且申请好域名的SSL证书,这些都可以通过阿里云完成。
13+
14+
### 服务器依赖安装
15+
16+
SSH到Ubuntu服务器上,首先安装一些基本的依赖:
17+
18+
```bash
19+
sudo apt-get update
20+
sudo apt-get install -y python3-pip apache2 libapache2-mod-wsgi-py3
21+
```
22+
23+
然后,使用git/wget/sftp或其他方式将服务端项目代码传输到服务器上,并且放到`/var/www/`目录下面;确保项目文件夹命名为`rpbg-server`(因为和`.conf`文件中指定的目录有关联)。进入项目目录`/var/www/rpbg-server`,运行:
24+
25+
```
26+
pip3 install -r requirements.txt
27+
```
28+
29+
安装python包依赖。然后运行:
30+
31+
```bash
32+
python3 manage.py makemigrations
33+
python3 manage.py migrate
34+
```
35+
36+
创建本地sqlite3数据库.
37+
38+
之后进入`/var/www`目录下,设置文件和目录的权限,运行:
39+
40+
```bash
41+
sudo cp rpbg-server/tti.conf /etc/apache2/sites-available/tti.conf
42+
sudo chgrp -R www-data rpbg-server
43+
sudo chmod -R 644 rpbg-server
44+
sudo find rpbg-server -type d | xargs chmod 755
45+
sudo chmod g+w rpbg-server
46+
sudo chmod g+w rpbg-server/db.sqlite3
47+
```
48+
49+
### 激活网站
50+
51+
```bash
52+
sudo service apache2 reload
53+
sudo a2dissite 000-default && sudo a2ensite tti
54+
sudo service apache2 restart
55+
```
56+
57+
就可以通过服务器的公网IP地址,对服务端发起请求了。需要访问我们之前定义好的path,否则是404.比如可以访问`http://{SERVER_IP}/zlai/api/test/`
58+
59+
### 启动https
60+
61+
上面的步骤执行完之后,我们可以通过http协议访问网站了,但依然不能使用域名访问。要想使用域名访问的话,首先需要配置域名解析,将域名解析到服务器的IP
62+
63+
然后SSH到服务器,需要将项目代码中提供的`default-ssl.conf`移动到`/etc/apache2/sites-available/`目录下,然后对其中的内容进行修改:
64+
65+
- 将所有出现`stable-ai.tech`的地方改为自己的域名
66+
67+
之后将https证书的相关文件放到`/etc/apache2/ssl/`路径下:
68+
69+
```conf
70+
SSLCertificateFile /etc/apache2/ssl/stable-ai.tech_public.crt
71+
SSLCertificateKeyFile /etc/apache2/ssl/stable-ai.tech.key
72+
SSLCertificateChainFile /etc/apache2/ssl/stable-ai.tech_chain.crt
73+
```
74+
75+
可以参考:[install-ssl-certificates-on-apache-servers](https://help.aliyun.com/zh/ssl-certificate/user-guide/install-ssl-certificates-on-apache-servers)
76+
77+
然后重启apache:
78+
79+
```
80+
a2ensite default-ssl
81+
sudo a2enmod ssl
82+
sudo service apache2 reload && sudo service apache2 restart
83+
```
84+
85+
此时应该就可以使用域名访问服务端接口了,可以到[https://www.myssl.cn/tools/check-server-cert.html](https://www.myssl.cn/tools/check-server-cert.html)检查https证书是否正确配置。
86+
87+
有了自己的域名之后,别忘了到前端项目代码的`util/session.tsx`中,更改`HOST`变量使其访问到自己的服务端接口。
88+
89+
### 服务端扩容
90+
91+
如果需要对服务端进行扩容,首选的扩容方式是使用CPU大一点的服务器。如果想要扩容到多台服务器的话,可以考虑使用阿里云的负载均衡,或者函数计算;此时需要将项目中使用的数据库配置为远程数据库而不是本地数据库;需要到项目中的`tti/settings.py`中对`DATABASES`进行配置,参考:[django databases](https://docs.djangoproject.com/en/4.1/ref/settings/#databases)
92+
93+
## 前端代码部署
94+
95+
首先,需要阅读[自定义模板中的前端代码](./5-nextjs-frontend.md)将代码配置好。
96+
97+
建立一个GitHub仓库(公有或者私有仓库都行),将前端的项目代码同步到这个仓库,也就是一级目录下包含`app/`, `package.json`等文件。
98+
99+
然后到[vercel](https://vercel.com/)绑定并授权自己的GitHub后,通过vercel部署一个新的项目,导入自己刚刚建立的仓库,然后等待vercel部署完成就行了。部署完之后可以通过vercel看到网页的访问URL
100+
101+
还可以到vercel的项目中的"settings-domains"中,添加自己的域名解析,自定义网站的URL
102+
103+
使用vercel部署无需关心扩容的问题,是自动扩缩容的。

side_project/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
* [项目模板预览](./3-template.md)
2222
* [如何自定义模板中的服务端代码](./4-django-server.md)
2323
* [如何自定义模板中的前端代码](./5-nextjs-frontend.md)
24-
* [部署到服务器、域名、前端部署(&如何扩容)](./6-deploy.md)
24+
* [部署到服务器、域名、前端部署](./6-deploy.md)
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
*token_secret.json
2+
*migrations*
3+
4+
# Byte-compiled / optimized / DLL files
5+
__pycache__/
6+
*.py[cod]
7+
*$py.class
8+
9+
# C extensions
10+
*.so
11+
12+
# Distribution / packaging
13+
.Python
14+
build/
15+
develop-eggs/
16+
dist/
17+
downloads/
18+
eggs/
19+
.eggs/
20+
lib/
21+
lib64/
22+
parts/
23+
sdist/
24+
var/
25+
wheels/
26+
share/python-wheels/
27+
*.egg-info/
28+
.installed.cfg
29+
*.egg
30+
MANIFEST
31+
32+
# PyInstaller
33+
# Usually these files are written by a python script from a template
34+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
35+
*.manifest
36+
*.spec
37+
38+
# Installer logs
39+
pip-log.txt
40+
pip-delete-this-directory.txt
41+
42+
# Unit test / coverage reports
43+
htmlcov/
44+
.tox/
45+
.nox/
46+
.coverage
47+
.coverage.*
48+
.cache
49+
nosetests.xml
50+
coverage.xml
51+
*.cover
52+
*.py,cover
53+
.hypothesis/
54+
.pytest_cache/
55+
cover/
56+
57+
# Translations
58+
*.mo
59+
*.pot
60+
61+
# Django stuff:
62+
*.log
63+
local_settings.py
64+
db.sqlite3
65+
db.sqlite3-journal
66+
67+
# Flask stuff:
68+
instance/
69+
.webassets-cache
70+
71+
# Scrapy stuff:
72+
.scrapy
73+
74+
# Sphinx documentation
75+
docs/_build/
76+
77+
# PyBuilder
78+
.pybuilder/
79+
target/
80+
81+
# Jupyter Notebook
82+
.ipynb_checkpoints
83+
84+
# IPython
85+
profile_default/
86+
ipython_config.py
87+
88+
# pyenv
89+
# For a library or package, you might want to ignore these files since the code is
90+
# intended to run in multiple environments; otherwise, check them in:
91+
# .python-version
92+
93+
# pipenv
94+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
95+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
96+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
97+
# install all needed dependencies.
98+
#Pipfile.lock
99+
100+
# poetry
101+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
102+
# This is especially recommended for binary packages to ensure reproducibility, and is more
103+
# commonly ignored for libraries.
104+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
105+
#poetry.lock
106+
107+
# pdm
108+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
109+
#pdm.lock
110+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
111+
# in version control.
112+
# https://pdm.fming.dev/#use-with-ide
113+
.pdm.toml
114+
115+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
116+
__pypackages__/
117+
118+
# Celery stuff
119+
celerybeat-schedule
120+
celerybeat.pid
121+
122+
# SageMath parsed files
123+
*.sage.py
124+
125+
# Environments
126+
.env
127+
.venv
128+
env/
129+
venv/
130+
ENV/
131+
env.bak/
132+
venv.bak/
133+
134+
# Spyder project settings
135+
.spyderproject
136+
.spyproject
137+
138+
# Rope project settings
139+
.ropeproject
140+
141+
# mkdocs documentation
142+
/site
143+
144+
# mypy
145+
.mypy_cache/
146+
.dmypy.json
147+
dmypy.json
148+
149+
# Pyre type checker
150+
.pyre/
151+
152+
# pytype static type analyzer
153+
.pytype/
154+
155+
# Cython debug symbols
156+
cython_debug/
157+
158+
# PyCharm
159+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
160+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
161+
# and can be added to the global gitignore or merged into this file. For a more nuclear
162+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
163+
#.idea/
164+
pic
165+
.idea
166+
167+
# mini program
168+
rpbg-mini-program-core/miniprogram_npm
169+
rpbg-mini-program-core/node_modules

0 commit comments

Comments
 (0)