瀏覽代碼

Исправлена отдача статики под Windows

Book Pauk 2 年之前
父節點
當前提交
061f50b714
共有 2 個文件被更改,包括 8 次插入3 次删除
  1. 5 0
      server/core/utils.js
  2. 3 3
      server/index.js

+ 5 - 0
server/core/utils.js

@@ -108,6 +108,10 @@ function gzipFile(inputFile, outputFile, level = 1) {
     });
 }
 
+function toUnixPath(dir) {
+    return dir.replace(/\\/g, '/');
+}
+
 module.exports = {
     sleep,
     versionText,
@@ -120,4 +124,5 @@ module.exports = {
     intersectSet,
     randomHexString,
     gzipFile,
+    toUnixPath,
 };

+ 3 - 3
server/index.js

@@ -208,10 +208,10 @@ function initStatic(app, config) {
     const filesDir = `${config.publicDir}/files`;
     app.use(express.static(config.publicDir, {
         setHeaders: (res, filePath) => {
-            res.set('Cache-Control', 'no-cache');
-            res.set('Expires', '-1');
+            //res.set('Cache-Control', 'no-cache');
+            //res.set('Expires', '-1');
 
-            if (path.dirname(filePath) == filesDir) {
+            if (utils.toUnixPath(path.dirname(filePath)) == utils.toUnixPath(filesDir)) {
                 res.set('Content-Encoding', 'gzip');
 
                 if (res.downFileName)