From 338d326971b19d38e3217c0acd6962f3ae7c938b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=BF=83=E5=AE=87?= Date: Wed, 22 May 2024 16:15:12 +0800 Subject: [PATCH] =?UTF-8?q?issue=E9=A1=B5=E9=9D=A2=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E7=A9=BA=E7=99=BD=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D=E3=80=81?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E7=AB=AF=E8=AF=B7=E6=B1=82=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?header=E8=A1=A8=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/index.js | 3 ++- server/setHead.js | 1 + src/forge/Main/Detail.js | 2 +- src/services/project.js | 39 +++++++++++++++------------------------ 4 files changed, 19 insertions(+), 26 deletions(-) diff --git a/server/index.js b/server/index.js index 61f3de042..4eccf0250 100644 --- a/server/index.js +++ b/server/index.js @@ -15,8 +15,9 @@ app.use('/build', express.static('build')); const options = (target) => { return { target: target, - changeOrigin: false, // 不允许在请求头中更改主机 + changeOrigin: process.env.NODE_ENV === 'dev' ? true : false, // 服务器不允许在请求头中更改主机 timeout: 30000, + secure: process.env.NODE_ENV === 'dev' ? false : true, // 忽略证书验证 onProxyRes: (proxyRes, req, res) => { // 代理成功后输出日志 Logger.info(`Proxy to ${req.url} responded with status ${proxyRes.statusCode}`); diff --git a/server/setHead.js b/server/setHead.js index 6695f0dc8..8b4f60e2e 100644 --- a/server/setHead.js +++ b/server/setHead.js @@ -47,4 +47,5 @@ export const changeHead = async ({ key }, params) => { default: return false } + return true } diff --git a/src/forge/Main/Detail.js b/src/forge/Main/Detail.js index 43617d788..24421f3e3 100644 --- a/src/forge/Main/Detail.js +++ b/src/forge/Main/Detail.js @@ -442,7 +442,7 @@ class Detail extends Component { defaultBranch: data.default_branch }); // seo优化设置 - let keyWords=`${owner},${projectsId}${ data.topics.length > 0 && ','}${ data.topics.length > 0 && data.topics.map(item => item.name).join(',') }`; + let keyWords=`${owner},${projectsId}${ data.topics && data.topics.length > 0 && ','}${ data.topics && data.topics.length > 0 && data.topics.map(item => item.name).join(',') }`; let title= `${owner}/${projectsId}${data.description?':'+data.description:''}`; setSeoMeta(keyWords,title,data.description || '',`/${owner}/${projectsId}`,owner,projectsId); } diff --git a/src/services/project.js b/src/services/project.js index caab6cbd0..779dfc3e6 100644 --- a/src/services/project.js +++ b/src/services/project.js @@ -23,70 +23,61 @@ axiosInstance.interceptors.response.use( } ) +const setHead = () => { + if (__SERVER__) { + axiosInstance.defaults.headers.cookie = domObj.window.document.cookie + axiosInstance.defaults.headers.isServer = true + } +} + // export async function getProjectFunc (owner, projectsId) { const url = `${baseUrl}/${owner}/${projectsId}/simple.json`; - if (__SERVER__) { - axiosInstance.defaults.headers.cookie = domObj.window.document.cookie - } + setHead() return axiosInstance.get(url); } export async function getProjectDetailFunc (owner, projectsId) { const url = `${baseUrl}/${owner}/${projectsId}/detail.json`; - if (__SERVER__) { - axiosInstance.defaults.headers.cookie = domObj.window.document.cookie - } + setHead() return axiosInstance.get(url); } export async function getProjectEntriesFunc (owner, projectsId, branch) { const url = `${baseUrl}/${owner}/${projectsId}/entries.json`; - if (__SERVER__) { - axiosInstance.defaults.headers.cookie = domObj.window.document.cookie - } + setHead() return axiosInstance.get(url, {params: { ref: branch }}); } export async function getBannerFunc (owner, projectsId) { const url = `${baseUrl}/${owner}/${projectsId}/menu_list.json`; - if (__SERVER__) { - axiosInstance.defaults.headers.cookie = domObj.window.document.cookie - } + setHead() return axiosInstance.get(url); } export async function getProjectReadMe (owner, projectsId, branch) { const url = `${baseUrl}/${owner}/${projectsId}/readme.json`; - if (__SERVER__) { - axiosInstance.defaults.headers.cookie = domObj.window.document.cookie - } + setHead() return axiosInstance.get(url, {params: { ref: branch }}); } export async function getOwnerInfo (owner) { const url = `${baseUrl}/owners/${owner}.json`; - if (__SERVER__) { - axiosInstance.defaults.headers.cookie = domObj.window.document.cookie - } + setHead() return axiosInstance.get(url); } export async function getMainInfos (deptId) { const url = `${baseZoneUrl}/zone/open/zoneKey/${deptId}`; - if (__SERVER__) { - axiosInstance.defaults.headers.cookie = domObj.window.document.cookie - } + setHead() return axiosInstance.get(url); } export async function getNewsDetail (id) { const url = `${baseZoneUrl}/cms/doc/open/${id}`; - if (__SERVER__) { - axiosInstance.defaults.headers.cookie = domObj.window.document.cookie - } + setHead() return axiosInstance.get(url); }