node/routes: Fix error handling

We should always send HTML if the user agent expects it.

If they do not, they should clearly indicate such via the Accept header.

Closes #2297
This commit is contained in:
Anmol Sethi
2020-11-13 15:32:47 -05:00
parent 7afa689285
commit 40a7c11ce3
2 changed files with 13 additions and 9 deletions

View File

@@ -48,8 +48,8 @@ router.all("*", (req, res, next) => {
// Assume anything that explicitly accepts text/html is a user browsing a
// page (as opposed to an xhr request). Don't use `req.accepts()` since
// *every* request that I've seen (in Firefox and Chromium at least)
// includes `*/*` making it always truthy.
if (typeof req.headers.accepts === "string" && req.headers.accepts.split(",").includes("text/html")) {
// includes `*/*` making it always truthy. Even for css/javascript.
if (req.headers.accept && req.headers.accept.includes("text/html")) {
// Let the login through.
if (/\/login\/?/.test(req.path)) {
return next()