diff --git a/.dockerignore b/.dockerignore index 888a9e2..cc95aff 100644 --- a/.dockerignore +++ b/.dockerignore @@ -11,3 +11,4 @@ coverage .nyc_output .DS_Store Thumbs.db +Dockerfile.dev diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..bc46601 --- /dev/null +++ b/.env.example @@ -0,0 +1,7 @@ +# API Base URL +# 默认值: https://thinkflow.lz-t.top +API_BASE_URL=https://thinkflow.lz-t.top + +# API Host (用于 Nginx 代理的 Host 头) +# 默认值: thinkflow.lz-t.top +API_HOST=thinkflow.lz-t.top diff --git a/Dockerfile b/Dockerfile index c5f7836..37959ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20-alpine +FROM node:20-alpine AS builder WORKDIR /app @@ -8,6 +8,18 @@ RUN npm install COPY . . -EXPOSE 5173 +RUN npm run build -CMD ["npm", "run", "dev", "--", "--host"] +FROM nginx:alpine + +COPY --from=builder /app/dist /usr/share/nginx/html + +COPY nginx.conf.template /etc/nginx/templates/nginx.conf.template + +COPY entrypoint.sh /docker-entrypoint.sh + +RUN chmod +x /docker-entrypoint.sh + +EXPOSE 80 + +CMD ["/docker-entrypoint.sh"] diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..61d8331 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,13 @@ +FROM node:20-alpine + +WORKDIR /app + +COPY package*.json ./ + +RUN npm install + +COPY . . + +EXPOSE 5173 + +CMD ["npm", "run", "dev", "--", "--host"] diff --git a/docker-compose.yml b/docker-compose.yml index 3a1ff47..9b0bdb9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,12 +5,10 @@ services: build: context: . dockerfile: Dockerfile - container_name: thinkflow-app + container_name: thinkflow ports: - - "5173:5173" - volumes: - - .:/app - - /app/node_modules + - "80:80" environment: - - NODE_ENV=development + - API_BASE_URL=${API_BASE_URL:-https://thinkflow.lz-t.top} + - API_HOST=${API_HOST:-thinkflow.lz-t.top} restart: unless-stopped diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..9af4537 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +envsubst '${API_BASE_URL} ${API_HOST}' < /etc/nginx/templates/nginx.conf.template > /etc/nginx/conf.d/default.conf + +exec nginx -g 'daemon off;' diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..b4a3624 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,29 @@ +server { + listen 80; + server_name localhost; + root /usr/share/nginx/html; + index index.html; + + location / { + try_files $uri $uri/ /index.html; + } + + location /api/chat { + proxy_pass https://thinkflow.lz-t.top/chat/completions; + proxy_set_header Host thinkflow.lz-t.top; + 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; + } + + location /api/image { + proxy_pass https://thinkflow.lz-t.top/images/generations; + proxy_set_header Host thinkflow.lz-t.top; + 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; + } + + gzip on; + gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; +} diff --git a/nginx.conf.template b/nginx.conf.template new file mode 100644 index 0000000..73ec9d3 --- /dev/null +++ b/nginx.conf.template @@ -0,0 +1,29 @@ +server { + listen 80; + server_name localhost; + root /usr/share/nginx/html; + index index.html; + + location / { + try_files $uri $uri/ /index.html; + } + + location /api/chat { + proxy_pass ${API_BASE_URL}/chat/completions; + proxy_set_header Host ${API_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; + } + + location /api/image { + proxy_pass ${API_BASE_URL}/images/generations; + proxy_set_header Host ${API_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; + } + + gzip on; + gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; +} diff --git a/src/composables/useThinkFlow.ts b/src/composables/useThinkFlow.ts index 705fe3d..25b2c63 100644 --- a/src/composables/useThinkFlow.ts +++ b/src/composables/useThinkFlow.ts @@ -49,12 +49,12 @@ export function useThinkFlow({ t, locale }: { t: Translate; locale: Ref */ const DEFAULT_CONFIG = { chat: { - baseUrl: 'https://thinkflow.lz-t.top/chat/completions', + baseUrl: '/api/chat', model: 'glm-4-flash', apiKey: '' }, image: { - baseUrl: 'https://thinkflow.lz-t.top/images/generations', + baseUrl: '/api/image', model: 'cogview-3-flash', apiKey: '' } diff --git a/vite.config.ts b/vite.config.ts index 94cf4db..79296c1 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,17 +1,32 @@ -import { defineConfig } from 'vite' +import { defineConfig, loadEnv } from 'vite' import vue from '@vitejs/plugin-vue' import path from 'path' -// https://vitejs.dev/config/ -export default defineConfig({ - plugins: [vue()], - server: { - host: '0.0.0.0', // 允许通过 IP 访问 - port: 5173, // 你可以根据需要修改端口 - }, - resolve: { - alias: { - '@': path.resolve(__dirname, './src'), +export default defineConfig(({ mode }) => { + const env = loadEnv(mode, process.cwd(), '') + + return { + plugins: [vue()], + server: { + host: '0.0.0.0', + port: 5173, + proxy: { + '/api/chat': { + target: env.VITE_API_BASE_URL || 'https://thinkflow.lz-t.top', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/api\/chat/, '/chat/completions') + }, + '/api/image': { + target: env.VITE_API_BASE_URL || 'https://thinkflow.lz-t.top', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/api\/image/, '/images/generations') + } + } }, - }, + resolve: { + alias: { + '@': path.resolve(__dirname, './src'), + }, + }, + } })