Files
mwy/readme.md

122 lines
2.7 KiB
Markdown
Raw Permalink Normal View History

2026-05-18 20:59:00 +08:00
# 手账站开发与运行
## 访问地址
| 环境 | 手账站 | Django Admin |
|------|--------|----------------|
2026-05-20 16:31:07 +08:00
| 本地开发 | http://localhost:5173 | http://localhost:8963/admin/ |
| Docker | http://localhost:8080 | http://localhost:8963/admin/ |
2026-05-18 20:59:00 +08:00
---
## 本地开发(推荐)
2026-05-20 16:31:07 +08:00
前后端各开一个终端。前端 Vite 会把 `/api``/media` 代理到 `http://127.0.0.1:8963`,需先启动后端。
2026-05-18 20:59:00 +08:00
### 后端Django
在项目根目录 `mwy` 下:
```powershell
cd backend
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt
python manage.py migrate
2026-05-20 16:31:07 +08:00
python manage.py runserver 8963
2026-05-18 20:59:00 +08:00
```
首次使用 Admin 可创建超级用户:
```powershell
python manage.py createsuperuser
```
导入示例时间线数据(会清空现有 `Memory` 记录):
```powershell
python manage.py seed_nepal_story
```
### 前端Vue + Vite
另开终端,在项目根目录下:
```powershell
cd frontend
npm install
npm run dev
```
浏览器打开 Vite 提示的地址(默认 http://localhost:5173
可选:指定 API 地址(一般不必,默认走代理 `/api`
```powershell
# .env 或 .env.local
2026-05-20 16:31:07 +08:00
# VITE_API_BASE_URL=http://127.0.0.1:8963/api
2026-05-18 20:59:00 +08:00
```
### 生产构建预览(可选)
```powershell
cd frontend
npm run build
npm run preview
```
---
## Docker 一键启动
在项目根目录:
```powershell
docker compose up --build
```
- 手账站http://localhost:8080
2026-05-20 16:31:07 +08:00
- Adminhttp://localhost:8963/admin/
2026-05-18 20:59:00 +08:00
数据与媒体挂在 Docker 卷 `backend_data`SQLite、`media`)。
---
2026-05-20 16:31:07 +08:00
## FRP 内网穿透frpc
通过 [frp](https://github.com/fatedier/frp) 把本机 Docker 里的手账站暴露到公网(需你已有 **frps** 服务端)。
1. 复制环境变量模板并填写 frps 信息:
```powershell
cp .env.example .env
# 编辑 .envFRP_SERVER_ADDR、FRP_SERVER_PORT、FRP_TOKEN、FRP_CUSTOM_DOMAIN、FRP_PUBLIC_ORIGIN
```
2. 先启动应用,再启用 frpc`frp` profile默认不启动
```powershell
docker compose up --build -d
docker compose --profile frp up -d
```
3. 在 frps 上为域名 `FRP_CUSTOM_DOMAIN` 配置 HTTP 入口后,用 `FRP_PUBLIC_ORIGIN` 访问手账站Admin 为 `{FRP_PUBLIC_ORIGIN 的 host}/admin/` 需经同一 HTTP 代理(当前穿透的是 frontend:80已包含 `/api``/media`)。
配置文件:`frpc/frpc.toml`。无域名时可在该文件中改用 TCP 代理(见文件内注释),并设置 `FRP_REMOTE_PORT`
---
2026-05-18 20:59:00 +08:00
## 常用命令速查
```powershell
# 后端目录 backend/ 下,且已激活虚拟环境
python manage.py migrate
2026-05-20 16:31:07 +08:00
python manage.py runserver 8963
2026-05-18 20:59:00 +08:00
python manage.py seed_nepal_story
python manage.py createsuperuser
# 前端目录 frontend/ 下
npm run dev
npm run build
```