Skip to content

Commit

Permalink
bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wurencaideli committed Jan 5, 2025
1 parent e6c5cd1 commit c77b753
Showing 1 changed file with 38 additions and 27 deletions.
65 changes: 38 additions & 27 deletions server/src/views/webSrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,52 @@ const { getReqlanguage } = require('../i18/index');
const { packageRequestHandler } = require('../common/packageRequestHandler');

/** 获取站点资源 */

[
{
r: '/base-naive-ui',
path: path.join(resourcesTools.getRootDir(), './web-base-naive-ui/dist'),
},
{ r: '/base-ant', path: path.join(resourcesTools.getRootDir(), './web-base-ant/dist') },
{ r: '/base', path: path.join(resourcesTools.getRootDir(), './web-base/dist') },
{ r: '/', path: path.join(resourcesTools.getRootDir(), './web/dist') },
].forEach((item) => {
const params = [express.static(item.path, {
/**
* TODO 注意nginx会缓存响应头带有Cache-Control的代理响应,所以对index.html友好
* 加个proxy_ignore_headers Cache-Control;就行了,让nginx不处理缓存让浏览器处理
*/
maxAge: '30d', // 设置缓存时间为 30 天
})];
if(item.r){
params.unshift(item.r);
}
router.use(...params);
});
[
{
r: '/base-naive-ui*',
path: path.join(resourcesTools.getRootDir(), './web-base-naive-ui/dist'),
},
{ r: '/base-ant*', path: path.join(resourcesTools.getRootDir(), './web-base-ant/dist') },
{ r: '/base*', path: path.join(resourcesTools.getRootDir(), './web-base/dist') },
{ r: '*', path: path.join(resourcesTools.getRootDir(), './web/dist') },
{ r: '', path: path.join(resourcesTools.getRootDir(), './web/dist') },
].forEach((item) => {
router.use(
item.r,
express.static(item.path, {
/**
* TODO 注意nginx会缓存响应头带有Cache-Control的代理响应,所以对index.html友好
* 加个proxy_ignore_headers Cache-Control;就行了,让nginx不处理缓存让浏览器处理
*/
maxAge: '30d', // 设置缓存时间为 30 天
}),
);
router.use(
item.r,
packageRequestHandler((req, res) => {
const filePath = path.join(item.path, 'index.html');
res.sendFile(filePath, (err) => {
if (!err) return;
res.json(
new publicReturn(404, {
msg: `没找到文件 ${item.r} index.html`,
lang: getReqlanguage(req),
}),
);
});
}),
);
const params = [packageRequestHandler((req, res) => {
const filePath = path.join(item.path, 'index.html');
res.sendFile(filePath, (err) => {
if (!err) return;
res.json(
new publicReturn(404, {
msg: `没找到文件 ${item.r} index.html`,
lang: getReqlanguage(req),
}),
);
});
})];
if(item.r){
params.unshift(item.r);
}
router.use(...params);
});

module.exports = router;

0 comments on commit c77b753

Please sign in to comment.