Skip to content

Node.js based forum software built for the modern web

feat: add 500 page for missing tpls, closes #12230

Barış Soner Uşaklı06221a0ddfd4
diff --git a/public/500.html b/public/500.html
new file mode 100644
index 0000000000..eec0e49f7a
--- /dev/null
+++ b/public/500.html
@@ -0,0 +1,41 @@
+<html>
+<head>
+ <title>Internal Server Error</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel="stylesheet" type="text/css" href="/assets/5xx.css" />
+
+ <script type="text/javascript">
+ window.onload = function() {
+ let count = 0;
+ const bounce = document.getElementById('click-me');
+ bounce.onclick = function() {
+ count++;
+ bounce.className = '';
+ setTimeout(function() {
+ bounce.className = 'animated bounce';
+ }, 50);
+
+ if (count > 5) {
+ document.getElementById('hide').className = '';
+ }
+ };
+ }
+ </script>
+</head>
+<body>
+ <div class="wrapper">
+ <div class="center">
+ <h1 id="click-me" class="animated bounce">500</h1>
+ <p>
+ <strong>Internal server error. </strong>
+ </p>
+ <p>
+ {message}
+ </p>
+ <p>
+ &nbsp;<small id="hide" class="hide">Alright. You can stop clicking... it's not going to make the site come back sooner!</small>
+ </p>
+ </div>
+ </div>
+</body>
+</html>
diff --git a/public/503.html b/public/503.html
index 43d1e648d9..51d0e52d53 100644
--- a/public/503.html
+++ b/public/503.html
@@ -2,147 +2,12 @@
<head>
<title>Excessive Load Warning</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
- <style type="text/css">
- body {
- background: #00A9EA;
- color: white;
- font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", Helvetica, Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
- text-align: center;
- -webkit-transform-style: preserve-3d;
- -moz-transform-style: preserve-3d;
- transform-style: preserve-3d;
- }
-
- h1 {
- font-size: 250px;
- color: #fff;
- opacity: 0.5;
- margin: 10px;
- cursor: pointer;
- -moz-user-select: none;
- -khtml-user-select: none;
- -webkit-user-select: none;
- }
-
- p {
- font-size: 20px;
- }
-
- p strong {
- font-size: 28px;
- }
-
- @media (max-width: 640px) {
- h1 {
- font-size: 125px;
- }
-
- p {
- font-size: 16px;
- }
-
- p strong {
- font-size: 20px;
- }
- }
-
- .center {
- position: relative;
- top: 50%;
- -webkit-transform: translateY(50%);
- -ms-transform: translateY(50%);
- transform: translateY(50%);
- }
-
- @-webkit-keyframes bounce {
- 0%, 20%, 53%, 80%, 100% {
- -webkit-transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
- transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
- -webkit-transform: translate3d(0,0,0);
- transform: translate3d(0,0,0);
- }
-
- 40%, 43% {
- -webkit-transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
- transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
- -webkit-transform: translate3d(0, -30px, 0);
- transform: translate3d(0, -30px, 0);
- }
-
- 70% {
- -webkit-transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
- transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
- -webkit-transform: translate3d(0, -15px, 0);
- transform: translate3d(0, -15px, 0);
- }
+ <link rel="stylesheet" type="text/css" href="/assets/5xx.css" />
- 90% {
- -webkit-transform: translate3d(0,-4px,0);
- transform: translate3d(0,-4px,0);
- }
- }
-
- @keyframes bounce {
- 0%, 20%, 53%, 80%, 100% {
- -webkit-transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
- transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
- -webkit-transform: translate3d(0,0,0);
- transform: translate3d(0,0,0);
- }
-
- 40%, 43% {
- -webkit-transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
- transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
- -webkit-transform: translate3d(0, -30px, 0);
- transform: translate3d(0, -30px, 0);
- }
-
- 70% {
- -webkit-transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
- transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
- -webkit-transform: translate3d(0, -15px, 0);
- transform: translate3d(0, -15px, 0);
- }
-
- 90% {
- -webkit-transform: translate3d(0,-4px,0);
- transform: translate3d(0,-4px,0);
- }
- }
-
- .bounce {
- -webkit-animation-name: bounce;
- animation-name: bounce;
- -webkit-transform-origin: center bottom;
- -ms-transform-origin: center bottom;
- transform-origin: center bottom;
- }
-
- .animated {
- -webkit-animation-duration: 1s;
- animation-duration: 1s;
- -webkit-animation-fill-mode: both;
- animation-fill-mode: both;
- }
-
- .animated.infinite {
- -webkit-animation-iteration-count: infinite;
- animation-iteration-count: infinite;
- }
-
- .animated.hinge {
- -webkit-animation-duration: 2s;
- animation-duration: 2s;
- }
-
- .hide {
- display: none;
- }
- </style>
<script type="text/javascript">
window.onload = function() {
- var count = 0,
- bounce = document.getElementById('click-me');
+ let count = 0;
+ const bounce = document.getElementById('click-me');
bounce.onclick = function() {
count++;
bounce.className = '';
diff --git a/public/5xx.css b/public/5xx.css
new file mode 100644
index 0000000000..faba67a114
--- /dev/null
+++ b/public/5xx.css
@@ -0,0 +1,135 @@
+body {
+ background: #00A9EA;
+ color: white;
+ font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", Helvetica, Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
+ text-align: center;
+ -webkit-transform-style: preserve-3d;
+ -moz-transform-style: preserve-3d;
+ transform-style: preserve-3d;
+}
+
+h1 {
+ font-size: 250px;
+ color: #fff;
+ opacity: 0.5;
+ margin: 10px;
+ cursor: pointer;
+ -moz-user-select: none;
+ -khtml-user-select: none;
+ -webkit-user-select: none;
+}
+
+p {
+ font-size: 20px;
+}
+
+p strong {
+ font-size: 28px;
+}
+
+@media (max-width: 640px) {
+ h1 {
+ font-size: 125px;
+ }
+
+ p {
+ font-size: 16px;
+ }
+
+ p strong {
+ font-size: 20px;
+ }
+}
+
+.center {
+ position: relative;
+ top: 50%;
+ -webkit-transform: translateY(50%);
+ -ms-transform: translateY(50%);
+ transform: translateY(50%);
+}
+
+@-webkit-keyframes bounce {
+ 0%, 20%, 53%, 80%, 100% {
+ -webkit-transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
+ transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
+ -webkit-transform: translate3d(0,0,0);
+ transform: translate3d(0,0,0);
+ }
+
+ 40%, 43% {
+ -webkit-transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
+ transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
+ -webkit-transform: translate3d(0, -30px, 0);
+ transform: translate3d(0, -30px, 0);
+ }
+
+ 70% {
+ -webkit-transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
+ transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
+ -webkit-transform: translate3d(0, -15px, 0);
+ transform: translate3d(0, -15px, 0);
+ }
+
+ 90% {
+ -webkit-transform: translate3d(0,-4px,0);
+ transform: translate3d(0,-4px,0);
+ }
+}
+
+@keyframes bounce {
+ 0%, 20%, 53%, 80%, 100% {
+ -webkit-transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
+ transition-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000);
+ -webkit-transform: translate3d(0,0,0);
+ transform: translate3d(0,0,0);
+ }
+
+ 40%, 43% {
+ -webkit-transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
+ transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
+ -webkit-transform: translate3d(0, -30px, 0);
+ transform: translate3d(0, -30px, 0);
+ }
+
+ 70% {
+ -webkit-transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
+ transition-timing-function: cubic-bezier(0.755, 0.050, 0.855, 0.060);
+ -webkit-transform: translate3d(0, -15px, 0);
+ transform: translate3d(0, -15px, 0);
+ }
+
+ 90% {
+ -webkit-transform: translate3d(0,-4px,0);
+ transform: translate3d(0,-4px,0);
+ }
+}
+
+.bounce {
+ -webkit-animation-name: bounce;
+ animation-name: bounce;
+ -webkit-transform-origin: center bottom;
+ -ms-transform-origin: center bottom;
+ transform-origin: center bottom;
+}
+
+.animated {
+ -webkit-animation-duration: 1s;
+ animation-duration: 1s;
+ -webkit-animation-fill-mode: both;
+ animation-fill-mode: both;
+}
+
+.animated.infinite {
+ -webkit-animation-iteration-count: infinite;
+ animation-iteration-count: infinite;
+}
+
+.animated.hinge {
+ -webkit-animation-duration: 2s;
+ animation-duration: 2s;
+}
+
+.hide {
+ display: none;
+}
\ No newline at end of file
diff --git a/src/controllers/errors.js b/src/controllers/errors.js
index cd377f5d59..35e2617bb1 100644
--- a/src/controllers/errors.js
+++ b/src/controllers/errors.js
@@ -1,8 +1,10 @@
'use strict';
+const fs = require('fs');
const nconf = require('nconf');
const winston = require('winston');
const validator = require('validator');
+const path = require('path');
const translator = require('../translator');
const plugins = require('../plugins');
const middleware = require('../middleware');
@@ -54,6 +56,12 @@ exports.handleErrors = async function handleErrors(err, req, res, next) { // esl
controllers['404'].handle404(req, res);
};
+ const notBuiltHandler = async () => {
+ let file = await fs.promises.readFile(path.join(__dirname, '../../public/500.html'), { encoding: 'utf-8' });
+ file = file.replace('{message}', 'Failed to lookup view! Did you run `./nodebb build`?');
+ return res.type('text/html').send(file);
+ };
+
const defaultHandler = async function () {
if (res.headersSent) {
return;
@@ -95,6 +103,8 @@ exports.handleErrors = async function handleErrors(err, req, res, next) { // esl
data.cases[err.code](err, req, res, defaultHandler);
} else if (err.message.startsWith('[[error:no-') && err.message !== '[[error:no-privileges]]') {
notFoundHandler();
+ } else if (err.message.startsWith('Failed to lookup view')) {
+ notBuiltHandler();
} else {
await defaultHandler();
}