Skip to content

CanvasAnvil is an open source AI diagram maker and flowchart generator - an infinite-canvas diagram editor and self-hosted drawio alternative that writes editable .drawio files. Text to diagram, then fix nodes, layout and labels in place. Also AI presentations, interior design CAD/BOM, posters and infographics.

deploy_fix

codingFeng101d5844d2dba5a
diff --git a/README.md b/README.md
index 38f4487..9bb4703 100644
--- a/README.md
+++ b/README.md
@@ -115,6 +115,7 @@ npm run build
## 常用脚本
- `npm run dev`:启动开发服务器
+- `npm start`:生产启动(静态站点 + API)
- `npm run build`:生产构建
- `npm run check`:TypeScript 类型检查
- `npm run lint`:ESLint 检查
diff --git a/api/server.ts b/api/server.ts
index ee8b4ca..baee947 100644
--- a/api/server.ts
+++ b/api/server.ts
@@ -1,5 +1,8 @@
-import express from "express";
+import express from "express";
import type { Response as ExpressResponse } from "express";
+import fs from "node:fs";
+import path from "node:path";
+import { fileURLToPath } from "node:url";
import { GET as getConfig } from "./routes/config";
import { POST as postVerifyAccessCode } from "./routes/verify-access-code";
import { POST as postLogFeedback } from "./routes/log-feedback";
@@ -8,9 +11,17 @@ import { POST as postLogFileParser } from "./routes/log-file-parser";
import { POST as postThirdPartyParser } from "./routes/third-party-parser";
import { POST as postChat } from "./routes/chat";
-const PORT = Number(process.env.API_PORT || 8787);
+const PORT = Number(process.env.PORT || process.env.API_PORT || 8080);
const BODY_LIMIT = process.env.API_BODY_LIMIT || "25mb";
+const __filename = fileURLToPath(import.meta.url);
+const __dirname = path.dirname(__filename);
+const defaultDistDir = path.resolve(__dirname, "../dist");
+const distDir = process.env.WEB_DIST_DIR
+ ? path.resolve(process.cwd(), process.env.WEB_DIST_DIR)
+ : defaultDistDir;
+const indexHtmlPath = path.join(distDir, "index.html");
+
const app = express();
app.use(express.json({ limit: BODY_LIMIT }));
@@ -107,6 +118,28 @@ app.get("/healthz", (_req, res) => {
res.json({ ok: true, ts: new Date().toISOString() });
});
+if (fs.existsSync(indexHtmlPath)) {
+ app.use(
+ express.static(distDir, {
+ index: false,
+ fallthrough: true,
+ }),
+ );
+
+ app.get(/.*/, (req, res, next) => {
+ if (req.path.startsWith("/api/") || req.path === "/healthz") {
+ next();
+ return;
+ }
+ res.sendFile(indexHtmlPath);
+ });
+} else {
+ console.warn(
+ `[server] dist not found at "${distDir}". Build web assets with "npm run build".`,
+ );
+}
+
app.listen(PORT, () => {
- console.log(`[api] listening on http://localhost:${PORT}`);
+ console.log(`[server] listening on http://localhost:${PORT}`);
+ console.log(`[server] web root: ${distDir}`);
});
diff --git a/deploy/README.md b/deploy/README.md
index 4f7da0c..e272d4e 100644
--- a/deploy/README.md
+++ b/deploy/README.md
@@ -1,63 +1,62 @@
# Deploy
-该项目包含两部分:
-
-- Web:Vite 构建后的静态站点(`dist/`)
-- API:Node/Express 服务(`/api/*` 路由)
-
-仅部署静态站点会导致依赖 `/api/*` 的功能不可用(例如 Flow Next 的配置与聊天接口)。
+当前部署方式为单服务:一个 Node 进程同时提供静态站点和 `/api/*`。
## 目录结构
-- `deploy/host/`:传统(主机/裸机)部署
-- `deploy/docker/`:Docker 镜像与 Compose 部署
+- `deploy/host/`:主机/裸机部署脚本与 Nginx 反向代理配置
+- `deploy/docker/`:Docker 镜像与 Compose 配置
-## 传统部署(Host)
+## Host(主机/裸机)
-1. 构建产物
+1. 安装依赖并构建
```bash
-./deploy/host/build.sh
+npm ci
+npm run build
```
-或(Windows)
+2. 启动服务
-```powershell
-.\deploy\host\build.ps1
+```bash
+npm start
```
-2. 上传 `dist/` 到服务器,例如:
+默认监听:`http://127.0.0.1:8080`
-- `/var/www/unified-ai-workspace/dist`
+可选环境变量:
-3. 启动 API 服务(建议使用 `pm2`/`systemd` 守护)
+- `PORT`:服务端口(默认 `8080`)
+- `API_BODY_LIMIT`:API 请求体大小限制(默认 `25mb`)
+- `WEB_DIST_DIR`:静态资源目录(默认 `./dist`)
-```bash
-npm ci
-npm run start:api
-```
+建议使用 `pm2` 或 `systemd` 守护。
-默认监听:`http://127.0.0.1:8787`
+3. (可选)Nginx 反向代理
-4. Nginx 配置
+将 `deploy/host/nginx.conf` 作为站点配置启用,重载 Nginx 后访问即可。
+该配置已包含:
-将 `deploy/host/nginx.conf` 作为站点配置启用(并按实际目录调整 `root`),其中已包含 `/api` 反向代理到 `127.0.0.1:8787`。重载 Nginx 后访问即可。
+- `client_max_body_size 25m`(避免文件上传出现 `413 Request Entity Too Large`)
+- `/api/chat` 的 `proxy_buffering off`(保证聊天流式输出实时返回)
-## Docker 部署
+## Docker
方式 A:Compose(推荐)
```bash
docker compose -f deploy/docker/docker-compose.yml up -d --build
```
+Compose 配置已内置 `/healthz` 健康检查。
-默认对外端口:`http://localhost:8080/`
-
-方式 B:仅启动 Web(不含 API,不推荐生产)
+方式 B:直接运行
```bash
docker build -f deploy/docker/Dockerfile -t unified-ai-workspace:latest .
-docker run --rm -p 8080:80 unified-ai-workspace:latest
+docker run --rm -p 8080:8080 unified-ai-workspace:latest
```
-Docker 构建使用项目根目录的 `.dockerignore` 以避免把 `node_modules/` 等无关内容打进构建上下文。
+默认访问:`http://localhost:8080/`
+
+Docker 构建使用项目根目录的 `.dockerignore`,避免把 `node_modules/` 等无关内容打进构建上下文。
+`deploy/docker/Dockerfile` 使用多阶段构建:构建阶段安装完整依赖,运行阶段仅安装生产依赖。
diff --git a/deploy/docker/Dockerfile b/deploy/docker/Dockerfile
index bdc9a87..d4d559c 100644
--- a/deploy/docker/Dockerfile
+++ b/deploy/docker/Dockerfile
@@ -3,13 +3,26 @@ FROM node:20-alpine AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
+
COPY . .
RUN npm run build
-FROM nginx:1.27-alpine
+FROM node:20-alpine AS runtime
+
+WORKDIR /app
+
+COPY package.json package-lock.json ./
+RUN npm ci --omit=dev
+
+COPY api ./api
+COPY src ./src
+COPY dist ./dist
+
+ENV NODE_ENV=production
+ENV PORT=8080
+ENV API_BODY_LIMIT=25mb
-COPY deploy/docker/nginx.conf /etc/nginx/conf.d/default.conf
-COPY --from=build /app/dist /usr/share/nginx/html
+EXPOSE 8080
-EXPOSE 80
+CMD ["npm", "start"]
diff --git a/deploy/docker/Dockerfile.api b/deploy/docker/Dockerfile.api
deleted file mode 100644
index 56a73c8..0000000
--- a/deploy/docker/Dockerfile.api
+++ /dev/null
@@ -1,12 +0,0 @@
-FROM node:20-alpine
-
-WORKDIR /app
-COPY package.json package-lock.json ./
-RUN npm ci
-
-COPY . .
-
-ENV API_PORT=8787
-EXPOSE 8787
-
-CMD ["npm", "run", "start:api"]
diff --git a/deploy/docker/docker-compose.yml b/deploy/docker/docker-compose.yml
index 9e72956..433fa52 100644
--- a/deploy/docker/docker-compose.yml
+++ b/deploy/docker/docker-compose.yml
@@ -1,21 +1,17 @@
services:
- api:
+ app:
build:
context: ../..
- dockerfile: deploy/docker/Dockerfile.api
+ dockerfile: deploy/docker/Dockerfile
environment:
- API_PORT: 8787
+ PORT: 8080
API_BODY_LIMIT: 25mb
- expose:
- - "8787"
- restart: unless-stopped
-
- web:
- build:
- context: ../..
- dockerfile: deploy/docker/Dockerfile
- depends_on:
- - api
ports:
- - "8080:80"
+ - "8080:8080"
+ healthcheck:
+ test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:8080/healthz >/dev/null || exit 1"]
+ interval: 30s
+ timeout: 5s
+ retries: 3
+ start_period: 15s
restart: unless-stopped
diff --git a/deploy/docker/nginx.conf b/deploy/docker/nginx.conf
deleted file mode 100644
index 1a0b386..0000000
--- a/deploy/docker/nginx.conf
+++ /dev/null
@@ -1,31 +0,0 @@
-server {
- listen 80;
- server_name _;
-
- root /usr/share/nginx/html;
- index index.html;
-
- location / {
- try_files $uri $uri/ /index.html;
- }
-
- location /api/ {
- proxy_pass http://api:8787;
- proxy_http_version 1.1;
- proxy_set_header Host $host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_set_header X-Forwarded-Proto $scheme;
- proxy_read_timeout 300s;
- }
-
- location = /healthz {
- proxy_pass http://api:8787/healthz;
- }
-
- location ~* \.(?:js|css|png|jpg|jpeg|gif|svg|webp|ico|woff2?|ttf|eot)$ {
- expires 30d;
- add_header Cache-Control "public, max-age=2592000, immutable";
- try_files $uri =404;
- }
-}
diff --git a/deploy/host/build.sh b/deploy/host/build.sh
index 1b6a4d2..6572650 100644
--- a/deploy/host/build.sh
+++ b/deploy/host/build.sh
@@ -1,6 +1,5 @@
-#!/usr/bin/env sh
+#!/usr/bin/env bash
set -euo pipefail
npm ci
npm run build
-
diff --git a/deploy/host/nginx.conf b/deploy/host/nginx.conf
index 7597ebd..ccf684e 100644
--- a/deploy/host/nginx.conf
+++ b/deploy/host/nginx.conf
@@ -1,16 +1,22 @@
server {
listen 80;
server_name _;
+ client_max_body_size 25m;
- root /var/www/unified-ai-workspace/dist;
- index index.html;
-
- location / {
- try_files $uri $uri/ /index.html;
+ location = /api/chat {
+ proxy_pass http://127.0.0.1:8080;
+ proxy_http_version 1.1;
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $scheme;
+ proxy_read_timeout 300s;
+ proxy_buffering off;
+ proxy_request_buffering off;
}
- location /api/ {
- proxy_pass http://127.0.0.1:8787;
+ location / {
+ proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@@ -20,13 +26,6 @@ server {
}
location = /healthz {
- proxy_pass http://127.0.0.1:8787/healthz;
- }
-
- location ~* \.(?:js|css|png|jpg|jpeg|gif|svg|webp|ico|woff2?|ttf|eot)$ {
- expires 30d;
- add_header Cache-Control "public, max-age=2592000, immutable";
- try_files $uri =404;
+ proxy_pass http://127.0.0.1:8080/healthz;
}
}
-
diff --git a/package-lock.json b/package-lock.json
index d5c472b..f86fdbc 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -51,6 +51,7 @@
"tailwind-merge": "^3.4.0",
"tailwindcss-animate": "^1.0.7",
"three": "^0.161.0",
+ "tsx": "^4.21.0",
"unpdf": "^1.4.0",
"zod": "^4.3.6",
"zustand": "^5.0.3"
@@ -74,7 +75,6 @@
"globals": "^16.0.0",
"postcss": "^8.5.6",
"tailwindcss": "^3.4.19",
- "tsx": "^4.21.0",
"typescript": "~5.8.3",
"typescript-eslint": "^8.30.1",
"vite": "^6.3.5",
@@ -4792,7 +4792,6 @@
"version": "4.13.6",
"resolved": "https://registry.npmmirror.com/get-tsconfig/-/get-tsconfig-4.13.6.tgz",
"integrity": "sha512-shZT/QMiSHc/YBLxxOkMtgSid5HFoauqCE3/exfsEcwg1WkeqjG+V40yBbBrsD+jW2HDXcs28xOfcbm2jI8Ddw==",
- "devOptional": true,
"license": "MIT",
"dependencies": {
"resolve-pkg-maps": "^1.0.0"
@@ -7466,7 +7465,6 @@
"version": "1.0.0",
"resolved": "https://registry.npmmirror.com/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz",
"integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==",
- "devOptional": true,
"license": "MIT",
"funding": {
"url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1"
@@ -8205,7 +8203,6 @@
"version": "4.21.0",
"resolved": "https://registry.npmmirror.com/tsx/-/tsx-4.21.0.tgz",
"integrity": "sha512-5C1sg4USs1lfG0GFb2RLXsdpXqBSEhAaA/0kPL01wxzpMqLILNxIxIOKiILz+cdg/pLnOUxFYOR5yhHU666wbw==",
- "devOptional": true,
"license": "MIT",
"dependencies": {
"esbuild": "~0.27.0",
@@ -8228,7 +8225,6 @@
"cpu": [
"ppc64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8245,7 +8241,6 @@
"cpu": [
"arm"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8262,7 +8257,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8279,7 +8273,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8296,7 +8289,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8313,7 +8305,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8330,7 +8321,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8347,7 +8337,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8364,7 +8353,6 @@
"cpu": [
"arm"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8381,7 +8369,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8398,7 +8385,6 @@
"cpu": [
"ia32"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8415,7 +8401,6 @@
"cpu": [
"loong64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8432,7 +8417,6 @@
"cpu": [
"mips64el"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8449,7 +8433,6 @@
"cpu": [
"ppc64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8466,7 +8449,6 @@
"cpu": [
"riscv64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8483,7 +8465,6 @@
"cpu": [
"s390x"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8500,7 +8481,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8517,7 +8497,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8534,7 +8513,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8551,7 +8529,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8568,7 +8545,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8585,7 +8561,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8602,7 +8577,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8619,7 +8593,6 @@
"cpu": [
"arm64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8636,7 +8609,6 @@
"cpu": [
"ia32"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8653,7 +8625,6 @@
"cpu": [
"x64"
],
- "dev": true,
"license": "MIT",
"optional": true,
"os": [
@@ -8667,7 +8638,6 @@
"version": "0.27.3",
"resolved": "https://registry.npmmirror.com/esbuild/-/esbuild-0.27.3.tgz",
"integrity": "sha512-8VwMnyGCONIs6cWue2IdpHxHnAjzxnw2Zr7MkVxB2vjmQ2ivqGFb4LEG3SMnv0Gb2F/G/2yA8zUaiL1gywDCCg==",
- "devOptional": true,
"hasInstallScript": true,
"license": "MIT",
"bin": {
diff --git a/package.json b/package.json
index 5b0a5c6..85c0ab5 100644
--- a/package.json
+++ b/package.json
@@ -8,7 +8,7 @@
"dev:full": "concurrently -k -n WEB,API -c cyan,magenta \"npm:dev:web\" \"npm:dev:api\"",
"dev:web": "vite",
"dev:api": "tsx watch api/server.ts",
- "start:api": "tsx api/server.ts",
+ "start": "tsx api/server.ts",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview",
@@ -58,6 +58,7 @@
"tailwind-merge": "^3.4.0",
"tailwindcss-animate": "^1.0.7",
"three": "^0.161.0",
+ "tsx": "^4.21.0",
"unpdf": "^1.4.0",
"zod": "^4.3.6",
"zustand": "^5.0.3"
@@ -81,7 +82,6 @@
"globals": "^16.0.0",
"postcss": "^8.5.6",
"tailwindcss": "^3.4.19",
- "tsx": "^4.21.0",
"typescript": "~5.8.3",
"typescript-eslint": "^8.30.1",
"vite": "^6.3.5",