root 3 weeks ago
parent
commit
5cc551394e
1 changed files with 9 additions and 3 deletions
  1. 9 3
      index.js

+ 9 - 3
index.js

@@ -17,14 +17,20 @@ const staticDir = path.join(__dirname, 'public');
 // 设置静态文件中间件
 app.use(express.static(staticDir, {
   // 缓存控制(1天)
-  maxAge: '1d',
+  //maxAge: '1d',
+  maxAge: 0,
+  cacheControl: false,
+  etag: false,
+  lastModified: false,
   // 设置索引文件
   index: ['index.html', 'index.htm'],
   // 自定义文件类型处理
   setHeaders: (res, filePath) => {
     const contentType = mime.contentType(path.extname(filePath)) || 'application/octet-stream';
     res.setHeader('Content-Type', contentType);
-    
+    res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
+    res.setHeader('Pragma', 'no-cache');
+    res.setHeader('Expires', '0');
     // 为特定文件类型添加额外头信息
     if (filePath.endsWith('.css')) {
       res.setHeader('X-Content-Type-Options', 'nosniff');
@@ -47,4 +53,4 @@ var httpsserver = http.createServer(httpsOption, app);
 app.use('/api', router);
 
 httpsserver.listen(port);
-console.log("Server running at http://" + host + ":" + port + "/");
+console.log("Server running at http://" + host + ":" + port + "/");