diff --git a/package-lock.json b/package-lock.json index b7b8368..9ac90ce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1618,9 +1618,9 @@ "dev": true }, "in-publish": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/in-publish/-/in-publish-2.0.0.tgz", - "integrity": "sha1-4g/146KvwmkDILbcVSaCqcf631E=" + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/in-publish/-/in-publish-2.0.1.tgz", + "integrity": "sha512-oDM0kUSNFC31ShNxHKUyfZKy8ZeXZBWMjMdZHKLOk13uvT27VTL/QzRGfRUcevJhpkZAvlhPYuXkF7eNWrtyxQ==" }, "indent-string": { "version": "2.1.0", @@ -2287,9 +2287,9 @@ } }, "minimist": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" }, "minipass": { "version": "3.1.1", @@ -2328,18 +2328,11 @@ "integrity": "sha512-imbHQNRglyaplMmjBLL3V5R6Bfq5oM+ivds3SKgc6oRtzErEnBUUc5No11Z2pilkUvl42gJvi285xTNswcKCMA==" }, "mkdirp": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.3.tgz", + "integrity": "sha512-P+2gwrFqx8lhew375MQHHeTlY8AuOJSrGf0R5ddkEndUkmwpgUob/vQuBD1V22/Cw1/lJr4x+EjllSezBThzBg==", "requires": { - "minimist": "0.0.8" - }, - "dependencies": { - "minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" - } + "minimist": "^1.2.5" } }, "ms": { @@ -2940,8 +2933,8 @@ } }, "pinski": { - "version": "github:cloudrac3r/pinski#1193025936cac58ac329b30e0749884bba6abb11", - "from": "github:cloudrac3r/pinski#1193025936cac58ac329b30e0749884bba6abb11", + "version": "github:cloudrac3r/pinski#4baee0a52b809ff9ac9767dbccc5addebc6c842a", + "from": "github:cloudrac3r/pinski#4baee0a52b809ff9ac9767dbccc5addebc6c842a", "requires": { "mime": "^2.4.4", "node-sass": "^4.13.1", @@ -5241,9 +5234,9 @@ } }, "ws": { - "version": "7.2.1", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.2.1.tgz", - "integrity": "sha512-sucePNSafamSKoOqoNfBd8V0StlkzJKL2ZAhGQinCfNQ+oacw+Pk7lcdAElecBF2VkLNZRiIb5Oi1Q5lVUVt2A==" + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.2.3.tgz", + "integrity": "sha512-HTDl9G9hbkNDk98naoR/cHDws7+EyYMOdL1BmjsZXRUjf7d+MficC4B7HLUPlSiho0vg+CWKrGIt/VJBd1xunQ==" }, "xml-js": { "version": "1.6.11", diff --git a/package.json b/package.json index 0b13df0..773ed0f 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "mixin-deep": "^2.0.1", "node-dir": "^0.1.17", "node-fetch": "^2.6.0", - "pinski": "github:cloudrac3r/pinski#1193025936cac58ac329b30e0749884bba6abb11", + "pinski": "github:cloudrac3r/pinski#4baee0a52b809ff9ac9767dbccc5addebc6c842a", "pug": "^2.0.4", "semver": "^7.1.2", "sharp": "^0.24.0", diff --git a/src/lib/utils/request.js b/src/lib/utils/request.js index ca5fa16..2f1a557 100644 --- a/src/lib/utils/request.js +++ b/src/lib/utils/request.js @@ -29,7 +29,8 @@ function request(url, options = {}, settings = {}) { headers: { "User-Agent": userAgent }, - followRedirect: false + followRedirect: false, + throwHttpErrors: false }, options)) } else { throw new Error("Invalid value for setting `request_backend`.") diff --git a/src/site/api/404.js b/src/site/api/404.js new file mode 100644 index 0000000..9b13c3c --- /dev/null +++ b/src/site/api/404.js @@ -0,0 +1,10 @@ +const {render} = require("pinski/plugins") +const constants = require("../../lib/constants") + +module.exports = [ + {route: "/404", methods: ["GET", "POST", "PATCH", "DELETE"], code: async ({url}) => { + const path = url.searchParams.get("pathname") + const couldBeUsername = path.match(`^/${constants.external.username_regex}$`) + return render(404, "pug/404.pug", {path, couldBeUsername}) + }} +] diff --git a/src/site/pug/404.pug b/src/site/pug/404.pug index c107fef..ff38cd4 100644 --- a/src/site/pug/404.pug +++ b/src/site/pug/404.pug @@ -1,3 +1,5 @@ +//- Needs path, couldBeUsername + include includes/error doctype html @@ -8,3 +10,5 @@ html body.error-page +error(404, "Page not found.") + if couldBeUsername + | Trying to access a user? #[a(href=`/u${path}`) Visit @#{path.slice(1)}] diff --git a/src/site/server.js b/src/site/server.js index 91513bc..e326e78 100644 --- a/src/site/server.js +++ b/src/site/server.js @@ -19,7 +19,6 @@ subdirs("pug", async (err, dirs) => { // need to check for and run db upgrades before anything starts using it await require("../lib/utils/upgradedb")() - pinski.addRoute("/404", "pug/404.pug", "pug") pinski.setNotFoundTarget("/404") pinski.addRoute("/static/css/main.css", "sass/main.sass", "sass") pinski.addPugDir("pug", dirs)