Skip to content

Commit

Permalink
wrong redirect in local server
Browse files Browse the repository at this point in the history
Part of mdn#350
  • Loading branch information
peterbe committed Dec 17, 2020
1 parent 058ed18 commit 72fbe7e
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,34 +192,23 @@ app.get("/*", async (req, res) => {
clearKumascriptRenderCache: true,
});
console.timeEnd(`buildDocumentFromURL(${lookupURL})`);
if (!built) {
return res
.status(404)
.sendFile(path.join(STATIC_ROOT, "en-us", "_spas", "404.html"));
if (built) {
document = built.doc;
bcdData = built.bcdData;
}
document = built.doc;
bcdData = built.bcdData;
} catch (error) {
console.error(`Error in buildDocumentFromURL(${lookupURL})`, error);
return res.status(500).send(error.toString());
}

if (!document) {
// redirect resolving can take some time, so we only do it when there's no document
// for the current route
const redirectURL = Redirect.resolve(lookupURL);
if (redirectURL !== lookupURL) {
return res.redirect(301, redirectURL + extraSuffix);
}

// It doesn't resolve to a file on disk and it's not a redirect.
// Try to send a slightly better error at least.
return res
.status(404)
.send(
`From URL ${lookupURL} no folder on disk could be found. ` +
`Tried to find a folder called ${Document.urlToFolderPath(lookupURL)}`
);
.sendFile(path.join(STATIC_ROOT, "en-us", "_spas", "404.html"));
}

if (bcdDataURL) {
Expand Down

0 comments on commit 72fbe7e

Please sign in to comment.