ci: 构建单镜像版本
1. 优化路由改为createWebHashHistory 2. 优化Dockerfile
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
# 构建阶段
|
||||
FROM node:18-alpine as build-stage
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 复制 package.json 和 package-lock.json(如果有)
|
||||
COPY package*.json ./
|
||||
|
||||
# 安装依赖
|
||||
RUN npm ci
|
||||
|
||||
# 复制项目文件
|
||||
COPY . .
|
||||
|
||||
# 构建应用
|
||||
RUN npm run build
|
||||
|
||||
# 生产阶段
|
||||
FROM nginx:stable-alpine as production-stage
|
||||
|
||||
# 复制自定义nginx配置
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
# 从构建阶段复制构建结果到nginx服务目录
|
||||
COPY --from=build-stage /app/dist /usr/share/nginx/html
|
||||
|
||||
# 暴露80端口
|
||||
EXPOSE 80
|
||||
|
||||
# 健康检查
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||
CMD wget --quiet --tries=1 --spider http://localhost:80 || exit 1
|
||||
|
||||
# 设定启动命令
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
@@ -1,94 +0,0 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
#access_log /var/log/nginx/host.access.log main;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# 缓存静态资源
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, max-age=31536000, immutable";
|
||||
}
|
||||
|
||||
# API请求代理到后端服务 - 使用相对路径
|
||||
location /api/ {
|
||||
proxy_pass http://backend:8888/api/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
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_cache_bypass $http_upgrade;
|
||||
proxy_read_timeout 300s;
|
||||
}
|
||||
|
||||
location /login {
|
||||
proxy_pass http://backend:8888/login;
|
||||
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_cache_bypass $http_upgrade;
|
||||
}
|
||||
|
||||
location /check_auth {
|
||||
proxy_pass http://backend:8888/check_auth;
|
||||
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_cache_bypass $http_upgrade;
|
||||
}
|
||||
|
||||
location /need_login {
|
||||
proxy_pass http://backend:8888/need_login;
|
||||
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_cache_bypass $http_upgrade;
|
||||
}
|
||||
|
||||
location /config {
|
||||
proxy_pass http://backend:8888/config;
|
||||
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_cache_bypass $http_upgrade;
|
||||
}
|
||||
|
||||
location /analyze {
|
||||
proxy_pass http://backend:8888/analyze;
|
||||
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_cache_bypass $http_upgrade;
|
||||
proxy_read_timeout 300s;
|
||||
}
|
||||
|
||||
location /test_api_connection {
|
||||
proxy_pass http://backend:8888/test_api_connection;
|
||||
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_cache_bypass $http_upgrade;
|
||||
}
|
||||
|
||||
# 所有其他路由返回index.html(SPA应用需要)
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# 错误页面
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root /usr/share/nginx/html;
|
||||
}
|
||||
}
|
||||
@@ -205,7 +205,6 @@ import {
|
||||
NFormItem,
|
||||
NInput,
|
||||
NInputNumber,
|
||||
NSwitch,
|
||||
NAlert,
|
||||
NDivider,
|
||||
NDropdown,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router';
|
||||
import { createRouter, createWebHashHistory } from 'vue-router';
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
import { apiService } from '@/services/api';
|
||||
import StockAnalysisApp from '@/components/StockAnalysisApp.vue';
|
||||
@@ -24,7 +24,7 @@ const routes: Array<RouteRecordRaw> = [
|
||||
];
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
history: createWebHashHistory(),
|
||||
routes
|
||||
});
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import axios from 'axios';
|
||||
import type { AnalyzeRequest, TestApiRequest, TestApiResponse, SearchResult, LoginRequest, LoginResponse } from '@/types';
|
||||
|
||||
// 在开发环境中使用完整URL
|
||||
const API_PREFIX = '';
|
||||
// API前缀
|
||||
const API_PREFIX = '/api';
|
||||
|
||||
// 创建axios实例
|
||||
const axiosInstance = axios.create({
|
||||
@@ -42,7 +42,7 @@ export const apiService = {
|
||||
// 用户登录
|
||||
login: async (request: LoginRequest): Promise<LoginResponse> => {
|
||||
try {
|
||||
const response = await axios.post(`${API_PREFIX}/login`, request);
|
||||
const response = await axiosInstance.post('/login', request);
|
||||
if (response.data.access_token) {
|
||||
localStorage.setItem('token', response.data.access_token);
|
||||
}
|
||||
@@ -64,7 +64,7 @@ export const apiService = {
|
||||
// 检查认证状态
|
||||
checkAuth: async (): Promise<boolean> => {
|
||||
try {
|
||||
const response = await axiosInstance.get(`${API_PREFIX}/check_auth`);
|
||||
const response = await axiosInstance.get('/check_auth');
|
||||
return response.data.authenticated === true;
|
||||
} catch (error) {
|
||||
// 认证失败,清除token
|
||||
@@ -82,7 +82,7 @@ export const apiService = {
|
||||
|
||||
// 分析股票
|
||||
analyzeStocks: async (request: AnalyzeRequest) => {
|
||||
return axiosInstance.post(`${API_PREFIX}/analyze`, request, {
|
||||
return axiosInstance.post('/analyze', request, {
|
||||
responseType: 'stream'
|
||||
});
|
||||
},
|
||||
@@ -90,7 +90,7 @@ export const apiService = {
|
||||
// 测试API连接
|
||||
testApiConnection: async (request: TestApiRequest): Promise<TestApiResponse> => {
|
||||
try {
|
||||
const response = await axiosInstance.post(`${API_PREFIX}/test_api_connection`, request);
|
||||
const response = await axiosInstance.post('/test_api_connection', request);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
if (error.response) {
|
||||
@@ -106,7 +106,7 @@ export const apiService = {
|
||||
// 搜索美股
|
||||
searchUsStocks: async (keyword: string): Promise<SearchResult[]> => {
|
||||
try {
|
||||
const response = await axiosInstance.get(`${API_PREFIX}/search_us_stocks`, {
|
||||
const response = await axiosInstance.get('/search_us_stocks', {
|
||||
params: { keyword }
|
||||
});
|
||||
return response.data.results || [];
|
||||
@@ -119,14 +119,14 @@ export const apiService = {
|
||||
// 获取配置
|
||||
getConfig: async () => {
|
||||
try {
|
||||
const response = await axios.get(`${API_PREFIX}/config`);
|
||||
const response = await axiosInstance.get('/config');
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('获取配置时出错:', error);
|
||||
return {
|
||||
announcement: '',
|
||||
default_api_url: '',
|
||||
default_api_model: 'gpt-3.5-turbo',
|
||||
default_api_model: '',
|
||||
default_api_timeout: '60'
|
||||
};
|
||||
}
|
||||
@@ -135,7 +135,7 @@ export const apiService = {
|
||||
// 检查是否需要登录
|
||||
checkNeedLogin: async (): Promise<boolean> => {
|
||||
try {
|
||||
const response = await axios.get(`${API_PREFIX}/need_login`);
|
||||
const response = await axiosInstance.get('/need_login');
|
||||
return response.data.require_login;
|
||||
} catch (error) {
|
||||
console.error('检查是否需要登录时出错:', error);
|
||||
|
||||
Reference in New Issue
Block a user