mm_statics 1.7.2 → 1.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +29 -18
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -298,7 +298,7 @@ Static.prototype._sendFile = async function (ctx, path) {
|
|
|
298
298
|
};
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
-
await send(ctx, path, config);
|
|
301
|
+
return await send(ctx, path, config);
|
|
302
302
|
};
|
|
303
303
|
|
|
304
304
|
/**
|
|
@@ -608,15 +608,6 @@ Static.prototype._handleCache = async function (url, ctx) {
|
|
|
608
608
|
return false;
|
|
609
609
|
};
|
|
610
610
|
|
|
611
|
-
/**
|
|
612
|
-
* 将路由路径转换为物理路径
|
|
613
|
-
* @param {string} path 文件路径
|
|
614
|
-
* @returns {string} 根路径
|
|
615
|
-
*/
|
|
616
|
-
Static.prototype.pathToRoot = function (path) {
|
|
617
|
-
return path.replace(this.config.path, "/");
|
|
618
|
-
}
|
|
619
|
-
|
|
620
611
|
/**
|
|
621
612
|
* 处理文件编译逻辑
|
|
622
613
|
* @param {string} path 文件路径
|
|
@@ -661,38 +652,58 @@ Static.prototype._handleCompiledResp = async function (url, path, body, ctx) {
|
|
|
661
652
|
}
|
|
662
653
|
};
|
|
663
654
|
|
|
655
|
+
/**
|
|
656
|
+
* 获取真实路径
|
|
657
|
+
* @param {string} path 文件路径
|
|
658
|
+
* @returns {string} 真实路径
|
|
659
|
+
*/
|
|
660
|
+
Static.prototype._getRealPath = function (path) {
|
|
661
|
+
return path.replace(this.config.path, "/");
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* 将路由路径转换为物理路径
|
|
666
|
+
* @param {string} path 文件路径
|
|
667
|
+
* @returns {string} 根路径
|
|
668
|
+
*/
|
|
669
|
+
Static.prototype._pathToRoot = function (path) {
|
|
670
|
+
return ("." + path).fullname(this.config.root);
|
|
671
|
+
}
|
|
672
|
+
|
|
664
673
|
/**
|
|
665
674
|
* 主处理函数
|
|
666
675
|
* @param {object} ctx Koa上下文对象
|
|
667
676
|
* @param {Function} next Koa中间件函数
|
|
668
677
|
*/
|
|
669
678
|
Static.prototype.main = async function (ctx, next) {
|
|
670
|
-
|
|
671
|
-
if (!
|
|
679
|
+
let url = ctx.url; // 使用完整URL(包含查询参数)
|
|
680
|
+
if (!ctx.path.startsWith(this.config.path)) {
|
|
672
681
|
await next();
|
|
673
|
-
return;
|
|
682
|
+
return '';
|
|
674
683
|
}
|
|
684
|
+
|
|
685
|
+
let path = this._getRealPath(ctx.path);
|
|
686
|
+
|
|
675
687
|
// 检查缓存
|
|
676
688
|
if (await this._handleCache(url, ctx)) {
|
|
677
|
-
return;
|
|
689
|
+
return this._pathToRoot(path);
|
|
678
690
|
}
|
|
679
691
|
|
|
680
|
-
const path = this.pathToRoot(ctx.path);
|
|
681
|
-
|
|
682
692
|
// 处理文件编译
|
|
683
693
|
let body = await this._handleFileCompile(path);
|
|
684
694
|
if (body) {
|
|
685
695
|
await this._handleCompiledResp(url, path, body, ctx);
|
|
686
|
-
return;
|
|
696
|
+
return this._pathToRoot(path);
|
|
687
697
|
}
|
|
688
698
|
|
|
689
699
|
// 直接发送文件
|
|
690
700
|
try {
|
|
691
|
-
await this._sendFile(ctx, path);
|
|
701
|
+
return await this._sendFile(ctx, path);
|
|
692
702
|
}
|
|
693
703
|
catch {
|
|
694
704
|
await next();
|
|
695
705
|
}
|
|
706
|
+
return '';
|
|
696
707
|
};
|
|
697
708
|
|
|
698
709
|
/**
|