Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc607e4ea3 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "trade-management-backend",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"description": "外贸供应链管理系统 - 后端",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
|
||||
+25
-2
@@ -126,8 +126,27 @@ function badRequest(message) {
|
||||
且表头必须正好在第一行。现在换成「关键词/正则 + 权重打分 + 表头行探测 + 数值列体检」,
|
||||
并支持 xlsx/xls —— 换行业只需改配置,不用改代码。 */
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 静态文件服务
|
||||
app.use(express.static(path.join(__dirname, '../frontend/dist')));
|
||||
//
|
||||
// 缓存分两档,因为这两类文件的更新方式完全不同:
|
||||
//
|
||||
// assets/* 文件名里带内容 hash(index-u1PUen4p.js),内容一变文件名就变,
|
||||
// 所以可以放心缓存一年;immutable 让浏览器连 304 都不用问。
|
||||
// express.static 默认是 max-age=0,等于每开一次页面就为每个
|
||||
// JS/CSS 跑一趟回源校验 —— 挂在 CDN 后面尤其浪费。
|
||||
//
|
||||
// index.html 文件名固定,里面引用的才是带 hash 的资源名。它**必须不缓存**,
|
||||
// 否则发了新版用户还拿着旧 index.html、指向旧资源,等于白更新。
|
||||
// ---------------------------------------------------------------------------
|
||||
const DIST_DIR = path.join(__dirname, '../frontend/dist');
|
||||
|
||||
app.use(express.static(DIST_DIR, {
|
||||
setHeaders(res, filePath) {
|
||||
if (filePath.endsWith('index.html')) res.setHeader('Cache-Control', 'no-cache');
|
||||
else res.setHeader('Cache-Control', 'public, max-age=31536000, immutable');
|
||||
}
|
||||
}));
|
||||
|
||||
// API 路由
|
||||
app.get('/api/health', (req, res) => {
|
||||
@@ -1801,8 +1820,12 @@ app.use((error, req, res, next) => {
|
||||
});
|
||||
|
||||
// SPA fallback - 所有未匹配的路由返回 index.html
|
||||
// 这里走的是 sendFile,不经过上面 express.static 的 setHeaders,
|
||||
// 所以 no-cache 得自己加一遍:/orders 这类深链拿到的也是 index.html,
|
||||
// 被缓存住的话发新版后用户照样打不到新资源。
|
||||
app.get('*', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, '../frontend/dist/index.html'));
|
||||
res.setHeader('Cache-Control', 'no-cache');
|
||||
res.sendFile(path.join(DIST_DIR, 'index.html'));
|
||||
});
|
||||
|
||||
// 启动服务器
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "trade-management-frontend",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"description": "外贸供应链管理系统 - 前端",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "happy-export",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"private": true,
|
||||
"description": "happy 出口通 —— 一体化外贸出口工具系统(SKU 管理 / 知识库 / 客户 CRM / 邮件开发 / AI 回复 / AI 生成)",
|
||||
"repository": {
|
||||
|
||||
Reference in New Issue
Block a user