Skip to content

Commit a5b029f

Browse files
committed
fix(server): 完善js文件404错误提示
1 parent 4095833 commit a5b029f

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

lib/commands/server.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,19 @@ exports.run = function (options) {
227227
if (Object.keys(nextConfig.entry).length === 0) {
228228
// 如果是js入口没找到,那肯定是出错了,这时候应该直接next让后面报错
229229
if (req.url.match(/\.js$/)) {
230-
next();
230+
res.writeHead(200, { 'Content-Type': 'text/html' });
231+
res.end('[ykit] - js入口未找到,请检查项目' + projectName + '的ykit配置文件.');
232+
} else {
233+
setTimeout(function () {
234+
promiseCache[projectName] ? Promise.all(promiseCache[projectName]).then(function () {
235+
// 统一去掉版本号
236+
req.url = req.url.replace(/@[\d\w]+(?=\.\w+$)/, '');
237+
next();
238+
}).catch(function (err) {
239+
throw err;
240+
}) : null;
241+
}, 1000);
231242
}
232-
setTimeout(function () {
233-
promiseCache[projectName] ? Promise.all(promiseCache[projectName]).then(function () {
234-
// 统一去掉版本号
235-
req.url = req.url.replace(/@[\d\w]+(?=\.\w+$)/, '');
236-
next();
237-
}).catch(function (err) {
238-
throw err;
239-
}) : null;
240-
}, 1000);
241243
} else {
242244
(function () {
243245
// 生成该请求的 promiseCache

lib/models/Project.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ var Project = function () {
172172
}
173173
});
174174
}
175+
175176
this.config.setExports(exports);
176177
this.config.setCompiler(userConfigObj.modifyWebpackConfig);
177178
this.config.setSync(userConfigObj.sync);

src/commands/server.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,19 +224,21 @@ exports.run = (options) => {
224224
if (Object.keys(nextConfig.entry).length === 0) {
225225
// 如果是js入口没找到,那肯定是出错了,这时候应该直接next让后面报错
226226
if (req.url.match(/\.js$/)) {
227-
next();
227+
res.writeHead(200, { 'Content-Type': 'text/html' });
228+
res.end('[ykit] - js入口未找到,请检查项目' + projectName + '的ykit配置文件.');
229+
} else {
230+
setTimeout(() => {
231+
promiseCache[projectName] ?
232+
Promise.all(promiseCache[projectName]).then(() => {
233+
// 统一去掉版本号
234+
req.url = req.url.replace(/@[\d\w]+(?=\.\w+$)/, '');
235+
next();
236+
}).catch((err) => {
237+
throw err;
238+
}) :
239+
null;
240+
}, 1000);
228241
}
229-
setTimeout(() => {
230-
promiseCache[projectName] ?
231-
Promise.all(promiseCache[projectName]).then(() => {
232-
// 统一去掉版本号
233-
req.url = req.url.replace(/@[\d\w]+(?=\.\w+$)/, '');
234-
next();
235-
}).catch((err) => {
236-
throw err;
237-
}) :
238-
null;
239-
}, 1000);
240242
} else {
241243
// 生成该请求的 promiseCache
242244
let resolve = null;

0 commit comments

Comments
 (0)