diff --git a/src/bk-user/Dockerfile b/src/bk-user/Dockerfile index 8988403bd..28bb9c0bb 100644 --- a/src/bk-user/Dockerfile +++ b/src/bk-user/Dockerfile @@ -1,10 +1,18 @@ -FROM python:3.10.12-slim-buster +FROM node:18.17.1-bullseye-slim AS StaticBuilding +ENV NPM_VERSION 9.6.7 + +COPY src/pages / +WORKDIR / +RUN npm install +RUN npm run build + +FROM python:3.10.12-slim-bullseye USER root RUN rm /etc/apt/sources.list && \ - echo "deb https://mirrors.tencent.com/debian buster main" >> /etc/apt/sources.list && \ - echo "deb https://mirrors.tencent.com/debian-security buster/updates main" >> /etc/apt/sources.list && \ - echo "deb https://mirrors.tencent.com/debian buster-updates main" >> /etc/apt/sources.list + echo "deb https://mirrors.tencent.com/debian bullseye main" >> /etc/apt/sources.list && \ + echo "deb https://mirrors.tencent.com/debian-security bullseye-security main" >> /etc/apt/sources.list && \ + echo "deb https://mirrors.tencent.com/debian bullseye-updates main" >> /etc/apt/sources.list RUN mkdir ~/.pip && printf '[global]\nindex-url = https://mirrors.tencent.com/pypi/simple/' > ~/.pip/pip.conf @@ -25,4 +33,7 @@ COPY src/bk-user/bkuser /app/bkuser COPY src/bk-user/bin /app/bin COPY src/bk-user/manage.py /app +COPY --from=StaticBuilding /dist /app/staticfiles +COPY --from=StaticBuilding /dist/index.html /app/templates/index.html + CMD ["bash", "/app/bin/start.sh"] diff --git a/src/bk-user/bkuser/common/views.py b/src/bk-user/bkuser/common/views.py index 5395678a2..fb16b1ff2 100644 --- a/src/bk-user/bkuser/common/views.py +++ b/src/bk-user/bkuser/common/views.py @@ -157,10 +157,11 @@ def get(self, request, *args, **kwargs): context = { # BK_DOMAIN "BK_DOMAIN": settings.BK_DOMAIN, + "BK_LOGIN_URL": settings.BK_LOGIN_URL.rstrip("/"), "BK_USER_URL": settings.BK_USER_URL.rstrip("/"), "AJAX_BASE_URL": settings.AJAX_BASE_URL.rstrip("/"), # 去除末尾的 /, 前端约定 - "STATIC_URL": settings.STATIC_URL.rstrip("/"), + "BK_STATIC_URL": settings.STATIC_URL.rstrip("/"), # 去除开头的 . document.domain需要 "SESSION_COOKIE_DOMAIN": settings.SESSION_COOKIE_DOMAIN.lstrip("."), # csrftoken name diff --git a/src/bk-user/bkuser/settings.py b/src/bk-user/bkuser/settings.py index 8d8a45e26..6d0701335 100644 --- a/src/bk-user/bkuser/settings.py +++ b/src/bk-user/bkuser/settings.py @@ -156,7 +156,7 @@ BK_DOMAIN = env.str("BK_DOMAIN", default="") # BK USER URL BK_USER_URL = env.str("BK_USER_URL") -AJAX_BASE_URL = SITE_URL + "api/v1" +AJAX_BASE_URL = "" # csrf _BK_USER_URL_PARSE_URL = urlparse(BK_USER_URL) diff --git a/src/pages/bk.config.js b/src/pages/bk.config.js index 8d700efba..0847129cd 100644 --- a/src/pages/bk.config.js +++ b/src/pages/bk.config.js @@ -8,6 +8,7 @@ module.exports = { cache: true, open: true, replaceStatic: true, + outputAssetsDirName: '', // webpack config 配置 configureWebpack() { diff --git a/src/pages/index.html b/src/pages/index.html index 73b2975f6..8679fc84a 100644 --- a/src/pages/index.html +++ b/src/pages/index.html @@ -1,8 +1,8 @@ - - + + index @@ -12,22 +12,10 @@ // 登录页面 window.BK_LOGIN_URL = '{{ BK_LOGIN_URL }}' // 开发环境域名 - window.AJAX_BASE_URL = '{{ AJAX_URL_PREFIX }}' + window.AJAX_BASE_URL = '{{ AJAX_BASE_URL }}' // 静态资源路径 - window.STATIC_URL = '{{ STATIC_URL }}' + window.BK_STATIC_URL = '{{ BK_STATIC_URL }}' window.CSRF_COOKIE_NAME = '{{ CSRF_COOKIE_NAME }}' - // var SITE_URL = '<%= process.env.BK_SITE_URL %>' - // var BK_STATIC_URL = '<%= process.env.BK_STATIC_URL %>' - // // 当前应用的环境,预发布环境为 stag,正式环境为 prod - // var BKPAAS_ENVIRONMENT = '<%= process.env.BK_PAAS_ENVIRONMENT %>' - // // EngineApp名称,拼接规则:bkapp-{appcode}-{BKPAAS_ENVIRONMENT} - // var BKPAAS_ENGINE_APP_NAME = '<%= process.env.BK_PAAS_ENGINE_APP_NAME %>' - // // 内部版对应ieod,外部版对应tencent,混合云版对应clouds - // var BKPAAS_ENGINE_REGION = '<%= process.env.BK_PAAS_ENGINE_REGION %>' - // // APP ID - // var BKPAAS_APP_ID = '<%= process.env.BK_PAAS_APP_ID %>' - // var BKPAAS_APP_SECRET = '<%= process.env.BK_PAAS_APP_SECRET %>' - // var BK_LOGIN_URL = '<%= process.env.BK_LOGIN_URL %>' diff --git a/src/pages/paas-server/index.js b/src/pages/paas-server/index.js index ba7cdc1f4..8d4e72e7b 100644 --- a/src/pages/paas-server/index.js +++ b/src/pages/paas-server/index.js @@ -94,5 +94,3 @@ app.set('view engine', 'html'); app.listen(PORT, () => { console.log(`App is running in port ${PORT}`); }); - - diff --git a/src/pages/src/http/fetch/index.ts b/src/pages/src/http/fetch/index.ts index fb3153bdf..abbfcba94 100644 --- a/src/pages/src/http/fetch/index.ts +++ b/src/pages/src/http/fetch/index.ts @@ -40,7 +40,7 @@ interface Http { const baseURL = /http(s)?:\/\//.test(window.AJAX_BASE_URL) ? window.AJAX_BASE_URL - : location.origin + window.STATIC_URL + window.AJAX_BASE_URL; + : location.origin + window.AJAX_BASE_URL; const axiosInstance = axios.create({ baseURL, @@ -48,7 +48,7 @@ const axiosInstance = axios.create({ xsrfCookieName: window.CSRF_COOKIE_NAME, xsrfHeaderName: 'X-CSRFToken', headers: { - 'X-CSRFToken': window.CSRF_COOKIE_NAME, + 'X-CSRFToken': Cookies.get(window.CSRF_COOKIE_NAME), 'x-requested-with': 'XMLHttpRequest', }, }); @@ -120,5 +120,5 @@ methods.forEach((method) => { }, }); }); - + export default http as Http;