diff --git a/build-scripts/vite.config.js b/build-scripts/vite.config.js index 51e35bb..0b8ee64 100644 --- a/build-scripts/vite.config.js +++ b/build-scripts/vite.config.js @@ -50,6 +50,7 @@ module.exports = defineConfig({ path.resolve(__dirname, '../client/js/entry-client-hydrogen.js'), path.resolve(__dirname, '../client/js/entry-client-room-directory.js'), path.resolve(__dirname, '../client/js/entry-client-room-alias-hash-redirect.js'), + path.resolve(__dirname, '../client/js/entry-client-timeout.js'), ], output: { assetFileNames: (chunkInfo) => { diff --git a/client/js/entry-client-timeout.js b/client/js/entry-client-timeout.js new file mode 100644 index 0000000..75ec846 --- /dev/null +++ b/client/js/entry-client-timeout.js @@ -0,0 +1,3 @@ +// Assets +import 'hydrogen-view-sdk/assets/theme-element-light.css'; +import '../css/styles.css'; diff --git a/server/hydrogen-render/render-page-html.js b/server/hydrogen-render/render-page-html.js index 62ec0a1..4135af2 100644 --- a/server/hydrogen-render/render-page-html.js +++ b/server/hydrogen-render/render-page-html.js @@ -8,7 +8,7 @@ const safeJson = require('../lib/safe-json'); const getDependenciesForEntryPointName = require('../lib/get-dependencies-for-entry-point-name'); const getFaviconAssetUrls = require('../lib/get-favicon-asset-urls'); -async function renderPageHtml({ +function renderPageHtml({ pageOptions, // Make sure you sanitize this before passing it to us bodyHtml, diff --git a/server/middleware/timeout-middleware.js b/server/middleware/timeout-middleware.js index 45dcd16..ce07468 100644 --- a/server/middleware/timeout-middleware.js +++ b/server/middleware/timeout-middleware.js @@ -5,7 +5,7 @@ const urlJoin = require('url-join'); const asyncHandler = require('../lib/express-async-handler'); const { getSerializableSpans, getActiveTraceId } = require('../tracing/tracing-middleware'); const sanitizeHtml = require('../lib/sanitize-html'); -const safeJson = require('../lib/safe-json'); +const renderPageHtml = require('../hydrogen-render/render-page-html'); const config = require('../lib/config'); const basePath = config.get('basePath'); @@ -19,7 +19,6 @@ async function timeoutMiddleware(req, res, next) { const timeoutId = setTimeout(() => { const traceId = getActiveTraceId(); const serializableSpans = getSerializableSpans(); - const serializedSpans = JSON.stringify(serializableSpans); let humanReadableSpans; if (serializableSpans.length > 0) { @@ -48,22 +47,9 @@ async function timeoutMiddleware(req, res, next) { humanReadableSpans = [noTracingDataAvailableItem]; } - const cspNonce = res.locals.cspNonce; - - const hydrogenStylesUrl = urlJoin(basePath, '/hydrogen-assets/hydrogen-styles.css'); - const stylesUrl = urlJoin(basePath, '/css/styles.css'); - - const pageHtml = ` - - - - - Server timeout - Matrix Public Archive - - - + const bodyHtml = ` ${/* We add the .hydrogen class here just to get normal body styles */ ''} - +

504: Server timeout

Server was unable to respond in time (${requestTimeoutMs / 1000}s)

These are the external API requests that made it slow:

@@ -76,14 +62,29 @@ async function timeoutMiddleware(req, res, next) { traceId ?? `none (tracing is probably not enabled)` }` )} - - - - +
`; + const pageOptions = { + title: `Server timeout - Matrix Public Archive`, + entryPoint: 'client/js/entry-client-timeout.js', + locationHref: urlJoin(basePath, req.originalUrl), + // We don't have a Matrix room so we don't know whether or not to index. Just choose + // a safe-default of false. + shouldIndex: false, + cspNonce: res.locals.cspNonce, + }; + + const pageHtml = renderPageHtml({ + pageOptions, + bodyHtml, + vmRenderContext: { + config: { + basePath, + }, + }, + }); + // 504 Gateway timeout res.status(504); res.set('Content-Type', 'text/html'); diff --git a/server/routes/client-side-room-alias-hash-redirect-route.js b/server/routes/client-side-room-alias-hash-redirect-route.js index 383fff6..deff295 100644 --- a/server/routes/client-side-room-alias-hash-redirect-route.js +++ b/server/routes/client-side-room-alias-hash-redirect-route.js @@ -24,16 +24,19 @@ function clientSideRoomAliasHashRedirectRoute(req, res) { }; const bodyHtml = ` -

- 404: Page not found. - -

-

If there was a #room_alias:server hash in the URL, we tried redirecting you to the right place.

-

- Otherwise, you're simply in a place that does not exist. - You can ${sanitizeHtml(`go back to the homepage.`)} -

- `; + ${/* We add the .hydrogen class here just to get normal body styles */ ''} +
+

+ 404: Page not found. + +

+

If there was a #room_alias:server hash in the URL, we tried redirecting you to the right place.

+

+ Otherwise, you're simply in a place that does not exist. + You can ${sanitizeHtml(`go back to the homepage.`)} +

+
+ `; const pageHtml = renderPageHtml({ pageOptions,