Skip to content

Commit a138998

Browse files
committed
feat(server): 支持 entry.key 路径匹配
1 parent 7555ce9 commit a138998

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lib/commands/server.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,12 @@ exports.run = function (options) {
225225
}
226226

227227
// 判断所请求的资源是否在入口配置中
228-
if (sysPath.normalize(entryPath) === sysPath.normalize(requestUrl)) {
228+
var matchingPath = sysPath.normalize(entryPath) === sysPath.normalize(requestUrl);
229+
var matchingPathWithoutVer = sysPath.normalize(entryPath) === sysPath.normalize(requestUrlNoVer);
230+
var matchingKeyWithoutVer = sysPath.normalize(requestUrlNoVer) === entryKey + sysPath.extname(requestUrl);
231+
if (matchingPath) {
229232
isRequestingEntry = true;
230-
} else if (sysPath.normalize(entryPath) === sysPath.normalize(requestUrlNoVer)) {
233+
} else if (matchingPathWithoutVer || matchingKeyWithoutVer) {
231234
req.url = req.url.replace(rversion, '');
232235
isRequestingEntry = true;
233236
}

src/commands/server.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,12 @@ exports.run = (options) => {
218218
}
219219

220220
// 判断所请求的资源是否在入口配置中
221-
if (sysPath.normalize(entryPath) === sysPath.normalize(requestUrl)) {
221+
const matchingPath = sysPath.normalize(entryPath) === sysPath.normalize(requestUrl);
222+
const matchingPathWithoutVer = sysPath.normalize(entryPath) === sysPath.normalize(requestUrlNoVer);
223+
const matchingKeyWithoutVer = sysPath.normalize(requestUrlNoVer) === entryKey + sysPath.extname(requestUrl);
224+
if (matchingPath) {
222225
isRequestingEntry = true;
223-
} else if (sysPath.normalize(entryPath) === sysPath.normalize(requestUrlNoVer)) {
226+
} else if (matchingPathWithoutVer || matchingKeyWithoutVer) {
224227
req.url = req.url.replace(rversion, '');
225228
isRequestingEntry = true;
226229
}

0 commit comments

Comments
 (0)