diff --git a/docker/50x.html b/docker/50x.html deleted file mode 100644 index a57c2f9..0000000 --- a/docker/50x.html +++ /dev/null @@ -1,19 +0,0 @@ - - - -Error - - - -

An error occurred.

-

Sorry, the page you are looking for is currently unavailable.
-Please try again later.

-

If you are the system administrator of this resource then you should check -the error log for details.

-

Faithfully yours, nginx.

- - diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index 0d4db7b..0000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM --platform=linux/arm64 docker.xuanyuan.run/library/nginx:1.29.0 - -COPY ./nginx.conf /etc/nginx/nginx.conf -COPY ./50x.html /usr/share/nginx/html/50x.html -COPY ./dist/ /usr/share/nginx/html/ - -EXPOSE 8080 - -CMD ["nginx","-g","daemon off;"] - -# docker build -t pcitc/itc-web:1.0.0 . - - diff --git a/docker/Dockerfile-node b/docker/Dockerfile-node deleted file mode 100644 index ed36e9c..0000000 --- a/docker/Dockerfile-node +++ /dev/null @@ -1,30 +0,0 @@ -FROM --platform=linux/arm64 docker.xuanyuan.run/library/node:20.15.1-slim - - -# 设置工作目录 -WORKDIR /app - - - -# 安装依赖(http-server和http-proxy-middleware) -RUN npm install http-server http-proxy-middleware --production - -# 复制自定义服务器脚本server.js -COPY ./server.js /app/ - - -# 复制静态文件到工作目录(根据实际项目调整,如dist目录) -# 假设静态文件在当前目录的dist文件夹下 -RUN mkdir -p /app/html - -COPY index.html /app/html/index.html - -# 暴露端口(与server.js中配置的port一致) -EXPOSE 8080 - -# 启动命令:通过node运行server.js -CMD ["node", "server.js"] - -# docker build -f Dockerfile-node -t node-http-server:1.0.3 . - - diff --git a/docker/Dockerfile-vue b/docker/Dockerfile-vue deleted file mode 100644 index 4fb17b8..0000000 --- a/docker/Dockerfile-vue +++ /dev/null @@ -1,13 +0,0 @@ -FROM --platform=linux/arm64 node-vue:1.0.0 - -WORKDIR /app - -COPY . . - -EXPOSE 8080 - -CMD ["npm","run","prod"] - -# docker build -f Dockerfile-vue -t pcitc/itc-web:1.0.2 . - - diff --git a/docker/build-docker-1.bat b/docker/build-docker-1.bat deleted file mode 100644 index 04730d0..0000000 --- a/docker/build-docker-1.bat +++ /dev/null @@ -1,67 +0,0 @@ -@echo off -chcp 65001 >nul 2>&1 :: UTF-8룬 -setlocal enabledelayedexpansion - -:: ·Ŀ¼ΪdockerĿ¼һ -set "ROOT_DIR=../" -set "DIST_DIR=%ROOT_DIR%dist" -set "DOCKER_DIR=%~dp0" -echo ====================== -echo Ŀ¼ %ROOT_DIR% -echo Ŀ¼ %DIST_DIR% -echo DockerĿ¼ %DOCKER_DIR% -echo ====================== - -if not exist "%DIST_DIR%" ( - echo δdistĿ¼ʧ - pause - exit /b 1 -) - -:: 2distdockerĿ¼ -echo ====================== -echo ʼdistĿ¼dockerĿ¼... -echo ====================== - -if exist "%DOCKER_DIR%dist" ( - echo ɵdistĿ¼... - rd /s /q "%DOCKER_DIR%dist" || ( - echo ޷ɾdistĿ¼رռõij - pause - exit /b 1 - ) -) - - -xcopy "%DIST_DIR%" "%DOCKER_DIR%dist" /e /i /h /r /y || ( - echo 󣺸distĿ¼ʧ - pause - exit /b 1 -) - -:: 3Docker -echo ====================== -echo ʼDocker... -echo ====================== -cd /d "%DOCKER_DIR%" || ( - echo ޷dockerĿ¼ %DOCKER_DIR% - pause - exit /b 1 -) - -where docker >nul 2>nul || ( - echo δҵdocker밲װDocker - pause - exit /b 1 -) - -docker build -t pcitc/itc-web:1.0.1 . || ( - echo docker build ִʧ - pause - exit /b 1 -) - -echo ====================== -echo ɣpcitc/itc-web:1.0.1 -echo ====================== -pause \ No newline at end of file diff --git a/docker/build-docker.bat b/docker/build-docker.bat deleted file mode 100644 index 48b3e6d..0000000 --- a/docker/build-docker.bat +++ /dev/null @@ -1,130 +0,0 @@ -@echo off -chcp 65001 >nul 2>&1 :: UTF-8룬 -setlocal enabledelayedexpansion - -:: ־ļ· -set "LOG_FILE=%~dp0docker_build.log" - -:: ʼ־ļ -echo ============================================== > "%LOG_FILE%" -echo ʼʱ: %date% %time% >> "%LOG_FILE%" -echo ============================================== >> "%LOG_FILE%" - -:: Ŀ¼ǰĿ¼ΪdockerĿ¼һ -set "ROOT_DIR=../" -set "DIST_DIR=%ROOT_DIR%dist" -set "DOCKER_DIR=%~dp0" - -:: Ŀ¼Ϣд־ -echo ====================== -echo Ŀ¼ %ROOT_DIR% -echo Ŀ¼ %DIST_DIR% -echo DockerĿ¼ %DOCKER_DIR% -echo ---------------------- -echo ====================== >> "%LOG_FILE%" -echo Ŀ¼ %ROOT_DIR% >> "%LOG_FILE%" -echo Ŀ¼ %DIST_DIR% >> "%LOG_FILE%" -echo DockerĿ¼ %DOCKER_DIR% >> "%LOG_FILE%" -echo ---------------------- >> "%LOG_FILE%" - -:: 1:ڸĿ¼ִnpm run build -echo ====================== -echo ʼִnpm run build... -echo ====================== -echo ====================== >> "%LOG_FILE%" -echo %date% %time% ʼִnpm run build... >> "%LOG_FILE%" -echo ====================== >> "%LOG_FILE%" - -cd /d "%ROOT_DIR%" || ( - echo ޷Ŀ¼ %ROOT_DIR% - echo %date% %time% ޷Ŀ¼ %ROOT_DIR% >> "%LOG_FILE%" - pause - exit /b 1 -) - -where npm >nul 2>nul || ( - echo δҵnpm밲װNode.jsû - echo %date% %time% δҵnpm밲װNode.jsû >> "%LOG_FILE%" - pause - exit /b 1 -) - -npm run build || ( - echo npm run build ִʧ - echo %date% %time% npm run build ִʧ >> "%LOG_FILE%" - pause - exit /b 1 -) - -echo -echo %date% %time% >> "%LOG_FILE%" -pause - -:: 2:distdockerĿ¼ -echo ====================== -echo ʼdistĿ¼dockerĿ¼... -echo ====================== -echo ====================== >> "%LOG_FILE%" -echo %date% %time% ʼdistĿ¼dockerĿ¼... >> "%LOG_FILE%" -echo ====================== >> "%LOG_FILE%" - -if exist "%DOCKER_DIR%dist" ( - echo ƳѴڵdistĿ¼... - echo %date% %time% ƳѴڵdistĿ¼... >> "%LOG_FILE%" - rd /s /q "%DOCKER_DIR%dist" || ( - echo ޷ɾdistĿ¼Ƿռ - echo %date% %time% ޷ɾdistĿ¼Ƿռ >> "%LOG_FILE%" - pause - exit /b 1 - ) -) - -pause - -xcopy "%DIST_DIR%" "%DOCKER_DIR%dist" /e /i /h /r /y || ( - echo 󣺸distĿ¼ʧ - echo %date% %time% 󣺸distĿ¼ʧ >> "%LOG_FILE%" - pause - exit /b 1 -) -echo %date% %time% distĿ¼ >> "%LOG_FILE%" - -:: 3:Docker -echo ====================== -echo ʼDocker... -echo ====================== -echo ====================== >> "%LOG_FILE%" -echo %date% %time% ʼDocker... >> "%LOG_FILE%" -echo ====================== >> "%LOG_FILE%" - -cd /d "%DOCKER_DIR%" || ( - echo ޷dockerĿ¼ %DOCKER_DIR% - echo %date% %time% ޷dockerĿ¼ %DOCKER_DIR% >> "%LOG_FILE%" - pause - exit /b 1 -) - -where docker >nul 2>&1 || ( - echo δҵdocker밲װDocker - echo %date% %time% δҵdocker밲װDocker >> "%LOG_FILE%" - pause - exit /b 1 -) - -docker build -t pcitc/itc-web:1.0.0 . || ( - echo docker build ִʧ - echo %date% %time% docker build ִʧ >> "%LOG_FILE%" - pause - exit /b 1 -) - -echo ====================== -echo ɹΪpcitc/itc-web:1.0.0 -echo ====================== -echo ====================== >> "%LOG_FILE%" -echo %date% %time% ɹΪpcitc/itc-web:1.0.0 >> "%LOG_FILE%" -echo ====================== >> "%LOG_FILE%" -echo ʱ: %date% %time% >> "%LOG_FILE%" -echo ============================================== >> "%LOG_FILE%" - -pause \ No newline at end of file diff --git a/docker/docker-itc-web.sh b/docker/docker-itc-web.sh deleted file mode 100644 index 555abd9..0000000 --- a/docker/docker-itc-web.sh +++ /dev/null @@ -1,135 +0,0 @@ -#!/bin/bash - -# 定义变量 -CONTAINER_NAME="itc-web" -IMAGE_NAME="pcitc/itc-web" -IMAGE_VERSION="1.0.0" -IMAGE_FULL="$IMAGE_NAME:$IMAGE_VERSION" -PORT=80 # 服务暴露端口 -CONTAINER_PORT=8080 # 服务暴露端口 -HTML_DIR="/docker-data/nginx/html" # 服务暴露端口 -CONF_DIR="/docker-data/nginx/conf" # 服务暴露端口 -TZ="Asia/Shanghai" # 时区设置 - -# 显示帮助信息 -show_help() { - echo "使用方法: $0 [操作类型]" - echo "操作类型:" - echo " deploy - 部署并启动服务容器" - echo " remove - 停止并删除容器及数据/日志目录" - echo " restart - 重启容器" - echo " logs - 查看容器日志" - echo " help - 显示帮助信息" -} - - - -# 部署服务 -deploy_service() { - # 创建数据和日志目录 - if [ ! -d "$HTML_DIR" ]; then - echo "创建html数据目录: $HTML_DIR" - mkdir -p "$HTML_DIR" - chmod 777 "$HTML_DIR" - fi - - # 创建数据和日志目录 - if [ ! -d "$CONF_DIR" ]; then - echo "创建配置数据目录: $CONF_DIR" - mkdir -p "$CONF_DIR" - chmod 777 "$CONF_DIR" - fi - - echo "部署镜像【$IMAGE_FULL】" - # 检查容器是否已存在,存在则停止并删除 - if [ "$(docker ps -aq -f name=$CONTAINER_NAME)" ]; then - echo "停止并删除现有容器: $CONTAINER_NAME" - docker stop $CONTAINER_NAME >/dev/null - docker rm $CONTAINER_NAME >/dev/null - fi - - # 启动服务容器 - echo "启动服务容器..." - docker run -d --privileged --restart always \ - --name $CONTAINER_NAME \ - -p $PORT:$CONTAINER_PORT \ - -v $HTML_DIR:/usr/share/nginx/html \ - -v $CONF_DIR:/etc/nginx \ - $IMAGE_FULL - - # 检查启动状态 - if [ "$(docker ps -aq -f name=$CONTAINER_NAME -f status=running)" ]; then - echo "服务启动成功!" - echo "容器名称: $CONTAINER_NAME" - echo "访问地址: http://localhost:$PORT" - echo "数据目录: $HTML_DIR" - echo "配置目录: $CONF_DIR" - else - echo "服务启动失败,日志如下:" - docker logs $CONTAINER_NAME - exit 1 - fi -} - -# 删除服务 -remove_service() { - # 检查容器是否存在 - if [ "$(docker ps -aq -f name=$CONTAINER_NAME)" ]; then - echo "停止容器: $CONTAINER_NAME" - docker stop $CONTAINER_NAME >/dev/null - - echo "删除容器: $CONTAINER_NAME" - docker rm $CONTAINER_NAME >/dev/null - else - echo "容器 $CONTAINER_NAME 不存在" - fi -} - -# 启动服务 -restart_service() { - if [ "$(docker ps -aq -f name=$CONTAINER_NAME)" ]; then - echo "重启容器: $CONTAINER_NAME" - docker restart $CONTAINER_NAME >/dev/null - else - echo "容器 $CONTAINER_NAME 不存在" - fi -} - -# 查看日志 -show_logs() { - if [ "$(docker ps -aq -f name=$CONTAINER_NAME)" ]; then - echo "查看 $CONTAINER_NAME 容器日志 (按 Ctrl+C 退出)..." - docker logs -f --tail 100 $CONTAINER_NAME - else - echo "容器 $CONTAINER_NAME 不存在" - fi -} - -# 主逻辑 -if [ $# -lt 1 ]; then - show_help - exit 1 -fi - -case "$1" in - deploy) - deploy_service - ;; - remove) - remove_service - ;; - restart) - restart_service - ;; - logs) - show_logs - ;; - help) - show_help - ;; - *) - echo "无效的操作类型: $1" - show_help - exit 1 - ;; -esac diff --git a/docker/index.html b/docker/index.html deleted file mode 100644 index 9a7f310..0000000 --- a/docker/index.html +++ /dev/null @@ -1,180 +0,0 @@ - - - - - - 静态服务器首页 - - - - - - -
-
-

- 静态服务器 -

-

- 已成功启动,可访问静态文件和通过代理接口与后端交互 -

-
-
- -
-
- -
-
- -
-

静态文件服务

-

- 该服务器可提供静态文件访问,当前根目录为 ./html -

- -
- - -
-
- -
-

API代理服务

-

- 所有 /api 前缀的请求将代理到: -
- http://10.4.126.116:23000 -

- - -
-
- -
-

- - 服务器信息 -

- -
-
- - - - - - diff --git a/docker/nginx.conf b/docker/nginx.conf deleted file mode 100644 index 73bc25b..0000000 --- a/docker/nginx.conf +++ /dev/null @@ -1,153 +0,0 @@ - -#user nobody; - -# 工作进程数:自动匹配CPU核心数(比固定值更灵活) -worker_processes auto; -# 绑定CPU核心(减少进程切换开销,0,1,2,3对应4核CPU) -worker_cpu_affinity 0001 0010 0100 1000; - -# 错误日志:开启并按级别分离(方便问题定位) -error_log /var/log/nginx/error.log notice; -pid /run/nginx.pid; - -# 全局资源限制(避免文件描述符不足) -worker_rlimit_nofile 65535; - -events { - # 每个工作进程最大连接数(结合系统ulimit调整) - worker_connections 8192; - # 高效事件模型(Linux推荐epoll,FreeBSD用kqueue) - use epoll; - # 一次性接受所有新连接(提高连接处理效率) - multi_accept on; -} - - -http { - include mime.types; - default_type application/octet-stream; - - # 日志格式优化:增加响应时间和 upstream 信息(便于性能分析) - log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - '$status $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for" ' - '$request_time $upstream_response_time'; - # 访问日志:开启(生产环境可按需关闭或调整路径) - access_log /var/log/nginx/access.log main; - - # 高效文件传输 - sendfile on; - # 静态文件传输优化(配合sendfile使用,减少TCP包数量) - tcp_nopush on; - # 动态内容优化(减少网络延迟) - tcp_nodelay on; - - # 长连接设置 - keepalive_timeout 65; # 连接超时时间 - keepalive_requests 1000; # 每个连接最大请求数(防止长连接占用) - keepalive_disable msie6; # 对老旧IE禁用长连接 - - # 客户端请求限制(防攻击) - client_max_body_size 100m; # 缩小上传限制(1024m过大,按需调整) - client_body_buffer_size 1m; # 客户端请求体缓冲区(原1024k保留,单位统一) - client_body_timeout 120s; # 客户端发送请求体超时 - client_header_timeout 120s; # 客户端发送请求头超时 - - - # Gzip压缩优化 - gzip on; - gzip_min_length 1k; # 最小压缩尺寸 - gzip_comp_level 5; # 压缩级别(平衡CPU和带宽) - gzip_types - text/plain text/css text/xml application/json application/javascript application/x-javascript text/javascript application/xml application/xml+rss text/rss; # 明确需要压缩的类型 - gzip_disable "MSIE [1-6]\."; # 禁用老旧IE压缩 - gzip_vary on; # 告诉代理服务器缓存压缩和非压缩版本 - gzip_buffers 16 8k; # 压缩缓冲区(默认值优化) - gzip_http_version 1.1; # 仅对HTTP/1.1及以上启用(避免兼容问题) - gzip_proxied any; # 对代理请求也启用压缩 - - # 隐藏nginx版本号(安全加固) - server_tokens off; - - # 通用安全响应头(全局生效) - add_header X-Frame-Options "SAMEORIGIN"; # 防止点击劫持 - add_header X-XSS-Protection "1; mode=block"; # 防XSS攻击 - add_header X-Content-Type-Options "nosniff"; # 防止MIME类型嗅探 - - # 反向代理配置 http://10.4.126.112:23000 - upstream upstream_name{ - server 172.20.0.2:8090; - keepalive 32; # 长连接池大小,减少连接建立开销 - keepalive_timeout 60s; - keepalive_requests 1000; - } - - # 虚拟主机配置 - server { - listen 8080; - listen [::]:8080; - # 建议替换为实际域名(如example.com),避免用localhost - server_name 10.4.126.116; - - # 网站根目录 - root /usr/share/nginx/html; - # 默认索引文件 - index index.html; - - # API接口代理配置(优化版) - location ^~/api/ { - # 代理目标地址 - proxy_pass http://upstream_name/; - - # 增强头信息转发 - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - - gzip off; # 禁用该接口的 gzip 压缩 - proxy_set_header Accept-Encoding ""; # 清除传给后端的 Accept-Encoding 头 - - # 超时设置(API专用,可根据业务调整) - proxy_connect_timeout 300s; - proxy_send_timeout 300s; - proxy_read_timeout 300s; - - - } - - # 主路径匹配 - location / { - try_files $uri $uri/ /index.html; # 适合SPA应用(如Vue/React) - # 缓存控制:动态内容不缓存 - add_header Cache-Control "no-cache, no-store, must-revalidate"; - add_header Pragma "no-cache"; - add_header Expires "0"; - } - - # 静态资源缓存优化(比原配置更精细) - location ~* \.(gif|jpg|jpeg|png|ico|svg|js|css|json|txt)$ { - # 缓存1天(可根据资源更新频率调整,如图片可设30d) - expires 1d; - add_header Cache-Control "public, max-age=86400"; - # 防盗链:只允许指定域名引用资源(替换为实际域名) - # valid_referers none blocked localhost example.com *.example.com; - # if ($invalid_referer) { - # return 403; - # } - } - - # 错误页面配置 - error_page 500 502 503 504 /50x.html; - location = /50x.html { - # 显式指定root(避免继承外层可能的变更) - root /usr/share/nginx/html; - } - - # 禁止访问隐藏文件(如.git .env等) - location ~ /\. { - deny all; - access_log off; - log_not_found off; - } - } -} diff --git a/docker/server.js b/docker/server.js deleted file mode 100644 index ebe39e3..0000000 --- a/docker/server.js +++ /dev/null @@ -1,179 +0,0 @@ -const http = require('http'); -const httpServer = require('http-server'); -const { createProxyMiddleware } = require('http-proxy-middleware'); -const path = require('path'); -const fs = require('fs'); -const { PassThrough } = require('stream'); - -const staticRoot = './html'; -const log = (message) => { - const timestamp = new Date().toISOString(); - console.log(`[${timestamp}] ${message}`); -}; - -const staticServer = httpServer.createServer({ - root: staticRoot, - showDir: false, - cors: true, - autoIndex: false -}); - -const proxyConfig = { - path: "/api", - target: "http://172.20.0.2:8090" -}; - -// 跟踪响应是否已处理 -const responseHandled = new WeakMap(); - -const apiProxy = createProxyMiddleware({ - target: proxyConfig.target, - changeOrigin: true, - pathRewrite: {'^/api': '' }, - logLevel: 'silent', - timeout: 120000, - // 禁用内置的分块处理,手动控制 - selfHandleResponse: true, - onTimeout: (req, res) => { - if (!responseHandled.has(res)) { - responseHandled.set(res, true); - res.writeHead(504, { 'Content-Type': 'application/json' }); - res.end(JSON.stringify({ error: 'Proxy timeout' })); - } - }, - on: { - proxyReq: (proxyReq, req, res) => { - const forwardedUrl = `${proxyReq.protocol}//${proxyReq.host}:${proxyReq.port}${proxyReq.path}`; - log(`转发请求到: ${proxyReq.method} ${forwardedUrl}`); - log(`请求头: ${JSON.stringify(req.headers, null, 2)}`); - - const contentType = req.headers['content-type'] || ''; - if (contentType.includes('application/json')) { - let requestBody = ''; - req.on('data', (chunk) => { requestBody += chunk.toString(); }); - req.on('end', () => { log(`请求体: ${requestBody}`); }); - } - }, - - proxyRes: (proxyRes, req, res) => { - if (responseHandled.has(res)) { - log(`已处理响应,跳过重复处理: ${req.url}`); - return; - } - responseHandled.set(res, false); - - log(`后端响应: ${proxyRes.statusCode} (${req.url})`); - log(`响应头: ${JSON.stringify(proxyRes.headers, null, 2)}`); - - const contentType = proxyRes.headers['content-type'] || ''; - const isChunked = proxyRes.headers['transfer-encoding'] === 'chunked'; - - // 复制响应头(排除可能引起冲突的头) - if (!res.headersSent) { - res.statusCode = proxyRes.statusCode; - Object.keys(proxyRes.headers).forEach(key => { - // 排除分块传输和连接控制头,由Node.js自动处理 - if (!['transfer-encoding', 'connection', 'content-length'].includes(key)) { - res.setHeader(key, proxyRes.headers[key]); - } - }); - } - - // 处理JSON响应 - if (contentType.includes('application/json')) { - let responseBody = ''; - const logStream = new PassThrough(); - - // 收集数据用于日志 - logStream.on('data', (chunk) => { - responseBody += chunk.toString(); - }); - - logStream.on('end', () => { - log(`响应体: ${responseBody}`); - }); - - // 分块传输处理 - if (isChunked) { - // 直接通过流转发,保留分块特性 - proxyRes.pipe(logStream).pipe(res); - } else { - // 非分块传输,收集完再发送 - proxyRes.on('data', (chunk) => { - responseBody += chunk.toString(); - }); - proxyRes.on('end', () => { - if (!responseHandled.get(res)) { - responseHandled.set(res, true); - log(`响应体: ${responseBody}`); - res.end(responseBody); - } - }); - } - } else { - // 非JSON响应直接转发 - proxyRes.pipe(res); - } - - // 监听响应结束 - proxyRes.on('end', () => { - responseHandled.set(res, true); - }); - - proxyRes.on('error', (err) => { - if (!responseHandled.get(res)) { - responseHandled.set(res, true); - log(`响应错误: ${err.message}`); - res.writeHead(500, { 'Content-Type': 'application/json' }); - res.end(JSON.stringify({ error: '响应处理错误' })); - } - }); - }, - - error: (err, req, res) => { - if (!responseHandled.has(res) || !responseHandled.get(res)) { - responseHandled.set(res, true); - log(`代理错误 [${err.code}]: ${err.message} (请求: ${req.url})`); - if (!res.headersSent) { - res.writeHead(500, { 'Content-Type': 'application/json' }); - } - res.end(JSON.stringify({ - error: '代理服务错误', - message: err.message - })); - } - } - } -}); - -const server = http.createServer((req, res) => { - if (req.url.startsWith(proxyConfig.path)) { - log(`收到代理请求: ${req.method} ${req.url}`); - return apiProxy(req, res); - } - else if (req.url === '' || req.url === '/' || req.url.endsWith('/')) { - log(`访问根路径,返回index.html: ${req.url}`); - const indexPath = path.join(staticRoot, 'index.html'); - - if (fs.existsSync(indexPath)) { - res.writeHead(200, { 'Content-Type': 'text/html' }); - fs.createReadStream(indexPath).pipe(res); - } else { - log(`警告: index.html不存在于 ${staticRoot}`); - res.writeHead(404, { 'Content-Type': 'text/plain' }); - res.end('index.html not found'); - } - } - else { - log(`处理静态文件请求: ${req.url}`); - staticServer.server.emit('request', req, res); - } -}); - -const port = 8080; -server.listen(port, () => { - log(`静态服务器已启动,监听端口 ${port}`); - log(`静态文件目录: ${path.resolve(staticRoot)}`); - log(`API代理目标: ${proxyConfig.target}`); - log(`访问地址: http://localhost:${port}`); -}); \ No newline at end of file