Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Prevent server errors if the URL has invalid characters (#1796)

Olga Bulatdfac0b79d44e
diff --git a/nuxt.config.ts b/nuxt.config.ts
index d7f2e3f8a..3646c52aa 100644
--- a/nuxt.config.ts
+++ b/nuxt.config.ts
@@ -15,6 +15,8 @@ import { env } from './src/utils/env'
import type { NuxtConfig, ServerMiddleware } from '@nuxt/types'
import type { LocaleObject } from '@nuxtjs/i18n'
+import type { IncomingMessage, NextFunction } from 'connect'
+import type http from 'http'
/**
* The default metadata for the site. Can be extended and/or overwritten per page. And even in components!
@@ -230,7 +232,24 @@ const config: NuxtConfig = {
* See the redirect module for more info.
* {@link https://github.com/nuxt-community/redirect-module#usage}
*/
- redirect: [{ from: '^/photos/(.*)$', to: '/image/$1', statusCode: 301 }],
+ redirect: {
+ rules: [
+ {
+ from: '^/photos/(.*)$',
+ to: '/image/$1',
+ statusCode: 301,
+ },
+ ],
+ // If the URL cannot be decoded, we call next() to show the client-side error page.
+ onDecodeError: (
+ _error: Error,
+ _req: IncomingMessage,
+ _res: http.ServerResponse,
+ next: NextFunction
+ ) => {
+ return next()
+ },
+ },
sentry: sentryConfig,
hooks: {
render: {