fix: 修复Docker中打包的前端请求地址为本地
Browse filesFiles changed (3)
- Dockerfile+13-5
- myUtils/auth.py+9-6
- sau_backend.py+6-2
12346 unmodified lines1112131415163 unmodified lines2021222324252627282918 unmodified lines4849505152535455FROM node:22.21.1 as builderWORKDIR /app6 unmodified linesENV NODE_ENV=productionENV PATH=/app/node_modules/.bin:$PATHRUN npm run build3 unmodified linesENV PLAYWRIGHT_BROWSERS_PATH=/opt/playwrightCOPY --from=builder /app/dist/index.html /appCOPY --from=builder /app/dist/assets /app/assetsCOPY --from=builder /app/dist/vite.svg /appRUN apt-get update && apt-get install -y --no-install-recommends libnss3 \libnspr4 \libdbus-1-3 \18 unmodified linesCOPY . .RUN cp conf.example.py conf.pyEXPOSE 5409CMD ["python", "sau_backend.py"]12346 unmodified lines11121314151617181920213 unmodified lines25262728293018 unmodified lines495051525354555657585960616263FROM node:22.21.1 AS builderWORKDIR /app6 unmodified linesENV NODE_ENV=productionENV PATH=/app/node_modules/.bin:$PATH# 替换前端中的地址RUN sed -i 's#\${baseUrl}##g' /app/src/views/AccountManagement.vueRUN sed -i "s#\${import\.meta\.env\.VITE_API_BASE_URL || 'http:\/\/localhost:5409'}##g" /app/src/api/material.jsRUN sed -i 's#localhost:5409##g' /app/.env.productionRUN npm run build3 unmodified linesENV PLAYWRIGHT_BROWSERS_PATH=/opt/playwrightRUN apt-get update && apt-get install -y --no-install-recommends libnss3 \libnspr4 \libdbus-1-3 \18 unmodified linesCOPY . .COPY --from=builder /app/dist/index.html /appCOPY --from=builder /app/dist/assets /app/assetsCOPY --from=builder /app/dist/vite.svg /app/assetsRUN cp conf.example.py conf.pyRUN mkdir -p /app/videoFileRUN mkdir -p /app/cookiesFileEXPOSE 5409CMD ["python", "sau_backend.py"]
4 unmodified lines567891011121314151617181918 unmodified lines3839404142434445468 unmodified lines55565758596061626312 unmodified lines7677787980818216 unmodified lines991001011021031041054 unmodified linesfrom playwright.async_api import async_playwrightfrom xhs import XhsClientfrom conf import BASE_DIRfrom utils.base_social_media import set_init_scriptfrom utils.log import tencent_logger, kuaishou_loggerfrom pathlib import Pathfrom uploader.xhs_uploader.main import sign_localasync def cookie_auth_douyin(account_file):async with async_playwright() as playwright:browser = await playwright.chromium.launch(headless=True)context = await browser.new_context(storage_state=account_file)context = await set_init_script(context)# 创建一个新的页面18 unmodified linesawait browser.close()return Falseasync def cookie_auth_tencent(account_file):async with async_playwright() as playwright:browser = await playwright.chromium.launch(headless=True)context = await browser.new_context(storage_state=account_file)context = await set_init_script(context)# 创建一个新的页面8 unmodified linestencent_logger.success("[+] cookie 有效")return Trueasync def cookie_auth_ks(account_file):async with async_playwright() as playwright:browser = await playwright.chromium.launch(headless=True)context = await browser.new_context(storage_state=account_file)context = await set_init_script(context)# 创建一个新的页面12 unmodified linesasync def cookie_auth_xhs(account_file):async with async_playwright() as playwright:browser = await playwright.chromium.launch(headless=True)context = await browser.new_context(storage_state=account_file)context = await set_init_script(context)# 创建一个新的页面16 unmodified linesreturn Trueasync def check_cookie(type,file_path):match type:# 小红书case 1:4 unmodified lines56789101112131415161718192018 unmodified lines394041424344454647488 unmodified lines5758596061626364656612 unmodified lines7980818283848516 unmodified lines1021031041051061071084 unmodified linesfrom playwright.async_api import async_playwrightfrom xhs import XhsClientfrom conf import BASE_DIR, LOCAL_CHROME_HEADLESSfrom utils.base_social_media import set_init_scriptfrom utils.log import tencent_logger, kuaishou_loggerfrom pathlib import Pathfrom uploader.xhs_uploader.main import sign_localasync def cookie_auth_douyin(account_file):async with async_playwright() as playwright:browser = await playwright.chromium.launch(headless=LOCAL_CHROME_HEADLESS)context = await browser.new_context(storage_state=account_file)context = await set_init_script(context)# 创建一个新的页面18 unmodified linesawait browser.close()return Falseasync def cookie_auth_tencent(account_file):async with async_playwright() as playwright:browser = await playwright.chromium.launch(headless=LOCAL_CHROME_HEADLESS)context = await browser.new_context(storage_state=account_file)context = await set_init_script(context)# 创建一个新的页面8 unmodified linestencent_logger.success("[+] cookie 有效")return Trueasync def cookie_auth_ks(account_file):async with async_playwright() as playwright:browser = await playwright.chromium.launch(headless=LOCAL_CHROME_HEADLESS)context = await browser.new_context(storage_state=account_file)context = await set_init_script(context)# 创建一个新的页面12 unmodified linesasync def cookie_auth_xhs(account_file):async with async_playwright() as playwright:browser = await playwright.chromium.launch(headless=LOCAL_CHROME_HEADLESS)context = await browser.new_context(storage_state=account_file)context = await set_init_script(context)# 创建一个新的页面16 unmodified linesreturn Trueasync def check_cookie(type, file_path):match type:# 小红书case 1:
31 unmodified lines323334353637383931 unmodified lines# 处理 favicon.ico 静态资源(未来打包用)@app.route('/favicon.ico')def favicon(filename):return send_from_directory(os.path.join(current_dir, 'assets'), 'favicon.ico')# (未来打包用)@app.route('/')31 unmodified lines32333435363738394041424331 unmodified lines# 处理 favicon.ico 静态资源(未来打包用)@app.route('/favicon.ico')def favicon():return send_from_directory(os.path.join(current_dir, 'assets'), 'vite.svg')@app.route('/vite.svg')def vite_svg():return send_from_directory(os.path.join(current_dir, 'assets'), 'vite.svg')# (未来打包用)@app.route('/')
Dockerfile+13-5
myUtils/auth.py+9-6
sau_backend.py+6-2