Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions packages/cli/src/lib/live-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function staticServer(root) {
}

function error(err) {
if (err.status === 404) return next();
// CHANGED: Removed if condition that checks for 404
next(err);
}

Expand Down Expand Up @@ -262,7 +262,20 @@ LiveServer.start = function(options) {
});
app.use(staticServerHandler) // Custom static server
.use(entryPoint(staticServerHandler, file))
.use(serveIndex(root, { icons: true }));
.use(serveIndex(root, { icons: true }))
// CHANGED: Added error handler to serve 404.html page
.use((err, req, res, next) => {
if (err.status === 404) {
res.statusCode = 404;
res.setHeader("Content-Type", "text/html");
const notFoundPage = path.join(root, "404.html");
fs.createReadStream(notFoundPage).pipe(res)
} else {
console.error(err.stack);
res.statusCode = err.status || 500;
res.end("Internal Server Error");
}
});

var server, protocol;
if (https !== null) {
Expand Down