Skip to content

Commit

Permalink
Fixes #58
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Mar 13, 2023
1 parent 8d55ea9 commit 9ff1596
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,27 +427,29 @@ class EleventyDevServer {
},
});

let match = this.mapUrlToFilePath(req.url);
debug( req.url, match );

if (match) {
if (match.statusCode === 200 && match.filepath) {
return this.renderFile(match.filepath, res);
}

// Redirects, usually for trailing slash to .html stuff
if (match.url) {
res.statusCode = match.statusCode;
res.setHeader("Location", match.url);
return res.end();
}

let raw404Path = this.getOutputDirFilePath("404.html");
if(match.statusCode === 404 && this.isOutputFilePathExists(raw404Path)) {
res.statusCode = match.statusCode;
return this.renderFile(raw404Path, res);
// middleware (maybe a serverless request) already set a body upstream, skip this part
if(!res._shouldForceEnd) {
let match = this.mapUrlToFilePath(req.url);
debug( req.url, match );

if (match) {
if (match.statusCode === 200 && match.filepath) {
return this.renderFile(match.filepath, res);
}

// Redirects, usually for trailing slash to .html stuff
if (match.url) {
res.statusCode = match.statusCode;
res.setHeader("Location", match.url);
return res.end();
}

let raw404Path = this.getOutputDirFilePath("404.html");
if(match.statusCode === 404 && this.isOutputFilePathExists(raw404Path)) {
res.statusCode = match.statusCode;
return this.renderFile(raw404Path, res);
}
}

}

if(res.body && !res.bodyUsed) {
Expand Down

0 comments on commit 9ff1596

Please sign in to comment.