Compare commits
2 Commits
4186c4289b
...
199dd8a9db
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
199dd8a9db | ||
|
|
8eb5499ecc |
@@ -11,3 +11,4 @@ coverage
|
|||||||
.nyc_output
|
.nyc_output
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
Dockerfile.dev
|
||||||
|
|||||||
26
Dockerfile
26
Dockerfile
@@ -1,4 +1,4 @@
|
|||||||
FROM node:20-alpine
|
FROM node:20-alpine AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
@@ -8,6 +8,26 @@ RUN npm install
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
EXPOSE 5173
|
RUN npm run build
|
||||||
|
|
||||||
CMD ["npm", "run", "dev", "--", "--host"]
|
FROM node:20-alpine
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY --from=builder /app/node_modules ./node_modules
|
||||||
|
COPY --from=builder /app/dist ./dist
|
||||||
|
COPY --from=builder /app/proxy-server.js ./
|
||||||
|
|
||||||
|
RUN npm install express cors http-proxy-middleware
|
||||||
|
|
||||||
|
RUN apk add --no-cache nginx
|
||||||
|
|
||||||
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
|
COPY start.sh /start.sh
|
||||||
|
|
||||||
|
RUN chmod +x /start.sh
|
||||||
|
|
||||||
|
EXPOSE 80 3000
|
||||||
|
|
||||||
|
CMD ["/start.sh"]
|
||||||
|
|||||||
@@ -5,12 +5,7 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
container_name: thinkflow-app
|
container_name: thinkflow
|
||||||
ports:
|
ports:
|
||||||
- "5173:5173"
|
- "80:80"
|
||||||
volumes:
|
|
||||||
- .:/app
|
|
||||||
- /app/node_modules
|
|
||||||
environment:
|
|
||||||
- NODE_ENV=development
|
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|||||||
29
nginx.conf
Normal file
29
nginx.conf
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name localhost;
|
||||||
|
root /app/dist;
|
||||||
|
index index.html;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri $uri/ /index.html;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /api/chat {
|
||||||
|
proxy_pass http://localhost:3000/api/chat;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /api/image {
|
||||||
|
proxy_pass http://localhost:3000/api/image;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
gzip on;
|
||||||
|
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
||||||
|
}
|
||||||
@@ -15,7 +15,10 @@
|
|||||||
"@vue-flow/minimap": "^1.5.4",
|
"@vue-flow/minimap": "^1.5.4",
|
||||||
"@vue-flow/node-resizer": "^1.5.0",
|
"@vue-flow/node-resizer": "^1.5.0",
|
||||||
"axios": "^1.6.7",
|
"axios": "^1.6.7",
|
||||||
|
"cors": "^2.8.5",
|
||||||
|
"express": "^4.18.2",
|
||||||
"html-to-image": "^1.11.13",
|
"html-to-image": "^1.11.13",
|
||||||
|
"http-proxy-middleware": "^2.0.6",
|
||||||
"lucide-vue-next": "^0.322.0",
|
"lucide-vue-next": "^0.322.0",
|
||||||
"markdown-it": "^14.1.0",
|
"markdown-it": "^14.1.0",
|
||||||
"vue": "^3.4.15",
|
"vue": "^3.4.15",
|
||||||
|
|||||||
45
proxy-server.js
Normal file
45
proxy-server.js
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const { createProxyMiddleware } = require('http-proxy-middleware');
|
||||||
|
const cors = require('cors');
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
const PORT = process.env.PROXY_PORT || 3000;
|
||||||
|
|
||||||
|
app.use(cors());
|
||||||
|
app.use(express.json());
|
||||||
|
|
||||||
|
app.use('/api/chat', createProxyMiddleware({
|
||||||
|
target: 'https://thinkflow.lz-t.top',
|
||||||
|
changeOrigin: true,
|
||||||
|
pathRewrite: {
|
||||||
|
'^/api/chat': '/chat/completions'
|
||||||
|
},
|
||||||
|
onProxyReq: (proxyReq, req, res) => {
|
||||||
|
const customBaseUrl = req.headers['x-custom-base-url'];
|
||||||
|
if (customBaseUrl) {
|
||||||
|
const url = new URL(customBaseUrl);
|
||||||
|
proxyReq.path = url.pathname;
|
||||||
|
proxyReq.setHeader('Host', url.host);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
app.use('/api/image', createProxyMiddleware({
|
||||||
|
target: 'https://thinkflow.lz-t.top',
|
||||||
|
changeOrigin: true,
|
||||||
|
pathRewrite: {
|
||||||
|
'^/api/image': '/images/generations'
|
||||||
|
},
|
||||||
|
onProxyReq: (proxyReq, req, res) => {
|
||||||
|
const customBaseUrl = req.headers['x-custom-base-url'];
|
||||||
|
if (customBaseUrl) {
|
||||||
|
const url = new URL(customBaseUrl);
|
||||||
|
proxyReq.path = url.pathname;
|
||||||
|
proxyReq.setHeader('Host', url.host);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
app.listen(PORT, () => {
|
||||||
|
console.log(`Proxy server running on port ${PORT}`);
|
||||||
|
});
|
||||||
@@ -49,12 +49,12 @@ export function useThinkFlow({ t, locale }: { t: Translate; locale: Ref<string>
|
|||||||
*/
|
*/
|
||||||
const DEFAULT_CONFIG = {
|
const DEFAULT_CONFIG = {
|
||||||
chat: {
|
chat: {
|
||||||
baseUrl: 'https://thinkflow.lz-t.top/chat/completions',
|
baseUrl: '/api/chat',
|
||||||
model: 'glm-4-flash',
|
model: 'glm-4-flash',
|
||||||
apiKey: ''
|
apiKey: ''
|
||||||
},
|
},
|
||||||
image: {
|
image: {
|
||||||
baseUrl: 'https://thinkflow.lz-t.top/images/generations',
|
baseUrl: '/api/image',
|
||||||
model: 'cogview-3-flash',
|
model: 'cogview-3-flash',
|
||||||
apiKey: ''
|
apiKey: ''
|
||||||
}
|
}
|
||||||
@@ -761,12 +761,18 @@ export function useThinkFlow({ t, locale }: { t: Translate; locale: Ref<string>
|
|||||||
const finalApiKey = apiConfig.mode === 'default' ? useConfig.apiKey || API_KEY : useConfig.apiKey
|
const finalApiKey = apiConfig.mode === 'default' ? useConfig.apiKey || API_KEY : useConfig.apiKey
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const headers: any = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${finalApiKey}`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiConfig.mode !== 'default' && useConfig.baseUrl) {
|
||||||
|
headers['X-Custom-Base-Url'] = useConfig.baseUrl
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(useConfig.baseUrl, {
|
const response = await fetch(useConfig.baseUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers,
|
||||||
'Content-Type': 'application/json',
|
|
||||||
Authorization: `Bearer ${finalApiKey}`
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
model: useConfig.model,
|
model: useConfig.model,
|
||||||
messages: [
|
messages: [
|
||||||
@@ -813,12 +819,19 @@ export function useThinkFlow({ t, locale }: { t: Translate; locale: Ref<string>
|
|||||||
const detail = node.data.description || ''
|
const detail = node.data.description || ''
|
||||||
const path = findPathToNode(nodeId)
|
const path = findPathToNode(nodeId)
|
||||||
const context = path.length > 5 ? `... -> ${path.slice(-4).join(' -> ')}` : path.join(' -> ')
|
const context = path.length > 5 ? `... -> ${path.slice(-4).join(' -> ')}` : path.join(' -> ')
|
||||||
|
|
||||||
|
const headers: any = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${finalApiKey}`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiConfig.mode !== 'default' && useConfig.baseUrl) {
|
||||||
|
headers['X-Custom-Base-Url'] = useConfig.baseUrl
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(useConfig.baseUrl, {
|
const response = await fetch(useConfig.baseUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers,
|
||||||
'Content-Type': 'application/json',
|
|
||||||
Authorization: `Bearer ${finalApiKey}`
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
model: useConfig.model,
|
model: useConfig.model,
|
||||||
prompt: t('prompts.image', { topic, detail, context })
|
prompt: t('prompts.image', { topic, detail, context })
|
||||||
@@ -869,12 +882,18 @@ export function useThinkFlow({ t, locale }: { t: Translate; locale: Ref<string>
|
|||||||
const path = findPathToNode(nodeId)
|
const path = findPathToNode(nodeId)
|
||||||
const context = path.join(' -> ')
|
const context = path.join(' -> ')
|
||||||
|
|
||||||
|
const headers: any = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${finalApiKey}`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiConfig.mode !== 'default' && useConfig.baseUrl) {
|
||||||
|
headers['X-Custom-Base-Url'] = useConfig.baseUrl
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(useConfig.baseUrl, {
|
const response = await fetch(useConfig.baseUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers,
|
||||||
'Content-Type': 'application/json',
|
|
||||||
Authorization: `Bearer ${finalApiKey}`
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
model: useConfig.model,
|
model: useConfig.model,
|
||||||
messages: [{ role: 'user', content: t('prompts.deepDivePrompt', { rootTopic, context, topic, detail }) }]
|
messages: [{ role: 'user', content: t('prompts.deepDivePrompt', { rootTopic, context, topic, detail }) }]
|
||||||
@@ -1031,12 +1050,18 @@ export function useThinkFlow({ t, locale }: { t: Translate; locale: Ref<string>
|
|||||||
const finalApiKey = apiConfig.mode === 'default' ? useConfig.apiKey || API_KEY : useConfig.apiKey
|
const finalApiKey = apiConfig.mode === 'default' ? useConfig.apiKey || API_KEY : useConfig.apiKey
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const headers: any = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${finalApiKey}`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiConfig.mode !== 'default' && useConfig.baseUrl) {
|
||||||
|
headers['X-Custom-Base-Url'] = useConfig.baseUrl
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(useConfig.baseUrl, {
|
const response = await fetch(useConfig.baseUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers,
|
||||||
'Content-Type': 'application/json',
|
|
||||||
Authorization: `Bearer ${finalApiKey}`
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
model: useConfig.model,
|
model: useConfig.model,
|
||||||
messages: [
|
messages: [
|
||||||
|
|||||||
5
start.sh
Normal file
5
start.sh
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
node proxy-server.js &
|
||||||
|
|
||||||
|
nginx -g 'daemon off;'
|
||||||
@@ -1,17 +1,32 @@
|
|||||||
import { defineConfig } from 'vite'
|
import { defineConfig, loadEnv } from 'vite'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
export default defineConfig(({ mode }) => {
|
||||||
export default defineConfig({
|
const env = loadEnv(mode, process.cwd(), '')
|
||||||
plugins: [vue()],
|
|
||||||
server: {
|
return {
|
||||||
host: '0.0.0.0', // 允许通过 IP 访问
|
plugins: [vue()],
|
||||||
port: 5173, // 你可以根据需要修改端口
|
server: {
|
||||||
},
|
host: '0.0.0.0',
|
||||||
resolve: {
|
port: 5173,
|
||||||
alias: {
|
proxy: {
|
||||||
'@': path.resolve(__dirname, './src'),
|
'/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'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user