Compare commits

...

2 Commits

Author SHA1 Message Date
JamesFlare1212
d0a0abed68 update: warp-proxy docker-compose.yaml 2026-04-06 16:43:10 -04:00
JamesFlare1212
4a97057825 feat: 添加可选的代理功能支持
新增功能:
- 集成 Cloudflare WARP socks5 代理服务
- 通过环境变量 USE_PROXY 控制代理开关
- 支持自定义 HTTP/HTTPS/SOCKS5 代理服务器
- 使用 docker compose profile 管理 proxy 服务

配置方式:
- USE_PROXY=true 启用代理
- ALL_PROXY/HTTP_PROXY/HTTPS_PROXY 自定义代理
- docker compose --profile proxy up 启动 warp 服务

文件变更:
- docker-compose.yaml: 添加 warp-proxy 服务
- playwright-auth.ts: 添加代理配置逻辑
- example.env: 添加代理环境变量
- PROXY.md: 使用文档
2026-04-06 16:37:54 -04:00
3 changed files with 52 additions and 5 deletions

View File

@@ -1,4 +1,17 @@
services: services:
# Warp Socks Proxy Service (Internal only - no external ports exposed)
warp-proxy:
image: ghcr.io/mon-ius/docker-warp-socks:v5
container_name: dsas-cca-warp-proxy
restart: unless-stopped
networks:
- cca_network
# Only expose port internally, not to host
expose:
- "9091"
profiles:
- proxy
app: app:
build: build:
context: . context: .
@@ -11,16 +24,24 @@ services:
environment: environment:
- NODE_ENV=production - NODE_ENV=production
- PLAYWRIGHT_BROWSERS_PATH=/ms-playwright - PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
# Proxy configuration (only active when USE_PROXY=true)
- USE_PROXY=${USE_PROXY:-false}
- HTTP_PROXY=${HTTP_PROXY:-}
- HTTPS_PROXY=${HTTPS_PROXY:-}
- ALL_PROXY=${ALL_PROXY:-}
restart: unless-stopped restart: unless-stopped
depends_on: depends_on:
redis: redis:
condition: service_healthy condition: service_healthy
warp-proxy:
condition: service_started
required: false
volumes: volumes:
- ./services/cookies.json:/usr/src/app/services/cookies.json - ./services/cookies.json:/usr/src/app/services/cookies.json
networks: networks:
- cca_network - cca_network
mem_limit: 1g extra_hosts:
cpus: 1.0 - "host.docker.internal:host-gateway"
redis: redis:
image: "redis:8.0-alpine" image: "redis:8.0-alpine"
@@ -36,7 +57,6 @@ services:
interval: 10s interval: 10s
timeout: 5s timeout: 5s
retries: 5 retries: 5
mem_limit: 256m
volumes: volumes:
redis_data: redis_data:

View File

@@ -17,3 +17,15 @@ CONCURRENT_API_CALLS=16
STAFF_UPDATE_INTERVAL_MINS=360 STAFF_UPDATE_INTERVAL_MINS=360
CLUB_UPDATE_INTERVAL_MINS=360 CLUB_UPDATE_INTERVAL_MINS=360
LOG_LEVEL=info # Example: 'debug', 'info', 'warn', 'error' LOG_LEVEL=info # Example: 'debug', 'info', 'warn', 'error'
# Proxy Configuration (Optional)
# Set USE_PROXY=true to enable proxy for Playwright requests
USE_PROXY=false
# Custom proxy server (default: socks5://warp-proxy:9091 when using warp-proxy service)
# Examples:
# HTTP: http://proxy.example.com:8080
# SOCKS5: socks5://proxy.example.com:1080
# Warp: socks5://warp-proxy:9091
ALL_PROXY=
HTTP_PROXY=
HTTPS_PROXY=

View File

@@ -8,16 +8,31 @@ const COOKIE_FILE_PATH = resolve(import.meta.dir, 'cookies.json');
let _inMemoryCookies: Cookie[] | null = null; let _inMemoryCookies: Cookie[] | null = null;
// Proxy configuration
const USE_PROXY = process.env.USE_PROXY === 'true';
const PROXY_SERVER = process.env.ALL_PROXY || process.env.HTTP_PROXY || `socks5://warp-proxy:9091`;
/** /**
* Login using Playwright and extract cookies * Login using Playwright and extract cookies
*/ */
export async function loginWithPlaywright(username: string, password: string): Promise<Cookie[]> { export async function loginWithPlaywright(username: string, password: string): Promise<Cookie[]> {
logger.info('Starting Playwright login process...'); logger.info('Starting Playwright login process...');
const browser = await chromium.launch({ const browserLaunchOptions: any = {
headless: true, headless: true,
args: ['--no-sandbox', '--disable-setuid-sandbox'] args: ['--no-sandbox', '--disable-setuid-sandbox']
}); };
// Configure proxy if enabled
if (USE_PROXY) {
logger.info(`Using proxy: ${PROXY_SERVER}`);
browserLaunchOptions.proxy = {
server: PROXY_SERVER,
bypass: 'localhost,127.0.0.1,::1'
};
}
const browser = await chromium.launch(browserLaunchOptions);
try { try {
const context = await browser.newContext({ const context = await browser.newContext({