# bread_web **Repository Path**: lsxh/bread_web ## Basic Information - **Project Name**: bread_web - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-07-09 - **Last Updated**: 2026-07-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Bread Calculator Web Web migration of your HarmonyOS bread app: - Recipe CRUD - Ingredient ratio and percentage - Scale ingredients by target total weight - Process steps and notes - Dough/oven temperature fields - User data isolation by account - Register / login / guest account Tech stack: - Backend: Go 1.20 + SQLite3 - Frontend: Vue 3 + Vite ## Project layout ```text bread_calculator/ ├── backend/ # Go API, config, SQLite DB, uploads ├── frontend/ # Vue 3 + Vite app ├── scripts/ # restart.sh / stop.sh helpers ├── Dockerfile # 生产镜像构建 ├── docker-compose.yml └── README.md ``` All commands below assume you are in the project root (`bread_calculator/`). ## Quick start ```bash ./scripts/restart.sh ./scripts/stop.sh ``` `restart.sh` stops any existing backend/frontend processes, rebuilds backend and frontend, then starts both: - Backend (serves built frontend from `frontend/dist`): `http://:9070` - Frontend dev server (hot reload while editing): `http://:5173` If you open `:9070`, you must run `./scripts/restart.sh` (or `npm run build`) after frontend code changes. Use `:5173` during development for instant updates. First-time frontend setup: ```bash cd frontend npm install cd .. ./scripts/restart.sh ``` ## 1) Run backend manually ```bash cd backend go mod tidy go run . ``` Primary config file: - Edit `backend/config.json` directly for day-to-day changes. Environment variables (optional, and will override `config.json`): - `PORT` (default `9070`) - `DB_PATH` (default `./bread.db`, relative to `backend/`) - `JWT_SECRET` (default `replace-this-secret`) - `GUEST_ENABLED` (`true` or `false`, default `true`) - `GUEST_TTL_DAYS` (default `7`, aligned with JWT expiry; `0` disables cleanup) - `GUEST_CLEANUP_INTERVAL_HOURS` (default `24`) - `POST_FEED_LIMIT` (default `20`) - `POST_MAX_IMAGES` (default `9`) - `POST_IMAGE_MAX_MB` (default `10`) - `POST_HOT_DAYS` (default `7`) - `FRONTEND_DIST` (default `../frontend/dist`) - `UPLOAD_DIR` (default `./uploads`, used for finished images) Runtime data paths (created under `backend/` when the server runs): - `backend/bread.db` — SQLite database - `backend/uploads/` — uploaded images and videos ## 2) Run frontend manually (dev) If you are not using `restart.sh`: ```bash cd frontend npm install npm run dev ``` Vite is already configured with `host: 0.0.0.0` and port `5173`, and proxies `/api` to `http://127.0.0.1:9070`. Visit: - `http://:5173` ## 3) Build production frontend ```bash cd frontend npm install npm run build ``` Then run the backend. It auto-serves `frontend/dist` when it exists. Visit: - `http://:9070` ## 4) LAN deployment notes - Open Linux firewall for backend port: - `sudo ufw allow 9070/tcp` - Use a strong `JWT_SECRET` in production. - Back up `backend/bread.db` regularly. ## 5) Docker 部署 镜像内已包含编译好的前端和后端,容器启动后访问: - `http://:9070` 数据目录(SQLite 数据库 + 上传文件)通过挂载 `/data` 持久化到主机。 ### 方式 A:docker compose(推荐) 在项目根目录执行: ```bash # 构建镜像并启动 docker compose up -d --build # docker compose up -d 启动,不重新构建 # 查看日志 docker compose logs -f # 停止 docker compose down ``` 默认把容器内 `/data` 映射到项目下的 `./data` 目录。要改主机目录,编辑 `docker-compose.yml`: ```yaml volumes: - /your/host/path:/data ``` 首次启动后,主机目录里会出现: - `bread.db` — 数据库 - `uploads/` — 上传的图片/视频 ### 方式 B:docker build + docker run ```bash # 1) 构建镜像 docker build -t bread-calculator:latest . # 2) 准备主机数据目录 mkdir -p /your/host/data # 3) 启动容器 docker run -d \ --name bread-calculator \ --restart unless-stopped \ -p 9070:9070 \ -v /your/host/data:/data \ -e JWT_SECRET='请改成强随机字符串' \ bread-calculator:latest ``` 常用环境变量(会覆盖 `config.json`): | 变量 | 默认值 | 说明 | |------|--------|------| | `PORT` | `9070` | 服务端口 | | `DB_PATH` | `/data/bread.db` | SQLite 文件路径(建议放在挂载卷里) | | `UPLOAD_DIR` | `/data/uploads` | 上传目录(建议放在挂载卷里) | | `JWT_SECRET` | `replace-this-secret` | 生产环境务必修改 | | `GUEST_ENABLED` | `true` | 是否允许游客登录 | | `GUEST_TTL_DAYS` | `7` | 游客账号保留天数(与 JWT 有效期一致;`0` 关闭自动清理) | | `GUEST_CLEANUP_INTERVAL_HOURS` | `24` | 游客清理任务执行间隔(小时) | ### Docker 常用命令 ```bash # 查看运行状态 docker ps # 查看日志 docker logs -f bread-calculator # 重启 docker restart bread-calculator # 停止并删除容器(数据仍在主机 /data 目录) docker rm -f bread-calculator ``` 备份时,直接复制主机上的 `data/bread.db` 和 `data/uploads/` 即可。