Skip to content

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

Redirect on image detail page (#492)

Krystle Salazar27e20e5f7b9a
diff --git a/README.md b/README.md
index e228fc016..c99201115 100644
--- a/README.md
+++ b/README.md
@@ -93,6 +93,12 @@ You will need to fix any linting issues before committing. We recommend formatti
All files and folders should be written in `kebab-case`, with the exception of Vue single file components. If it ends in `.vue`, please use `PascalCase`. This distinction makes our component files stand out clearly and is [recommended by the Vue community](https://vuejs.org/v2/style-guide/#Single-file-component-filename-casing-strongly-recommended).
+## Redirects
+
+| From | To | Status code | Setup level |
+| ------------ | ----------- | ----------- | ---------------------- |
+| /photos/\_id | /image/\_id | 301 | Nuxt server middleware |
+
## Contributing
Pull requests are welcome! Feel free to [join us on Slack](https://make.wordpress.org/chat/) and discuss the project with the engineers and community members on #openverse.
diff --git a/nuxt.config.js b/nuxt.config.js
index c6b25edee..ac7623cd2 100644
--- a/nuxt.config.js
+++ b/nuxt.config.js
@@ -166,7 +166,12 @@ export default {
styleResources: {
scss: ['./styles/utilities/all.scss'],
},
- modules: ['@nuxtjs/sentry', '@nuxtjs/i18n', '@nuxtjs/sitemap'],
+ modules: [
+ '@nuxtjs/i18n',
+ '@nuxtjs/redirect-module',
+ '@nuxtjs/sentry',
+ '@nuxtjs/sitemap',
+ ],
serverMiddleware: [
{ path: '/healthcheck', handler: '~/server-middleware/healthcheck.js' },
],
@@ -202,6 +207,12 @@ export default {
baseUrl: 'http://localhost:8443',
vueI18n: '~/plugins/vue-i18n.js',
},
+ /**
+ * Map the old route for /photos/_id page to /image/_id permanently to keep links working.
+ * See the redirect module for more info.
+ * {@link https://github.com/nuxt-community/redirect-module#usage}
+ */
+ redirect: [{ from: '^/photos/(.*)$', to: '/image/$1', statusCode: 301 }],
sentry: {
dsn:
process.env.SENTRY_DSN ||
diff --git a/package-lock.json b/package-lock.json
index 55a33f523..f3b0d5892 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -11,6 +11,7 @@
"@nuxt/components": "^2.1.6",
"@nuxtjs/composition-api": "^0.27.0",
"@nuxtjs/i18n": "^7.0.3",
+ "@nuxtjs/redirect-module": "^0.3.1",
"@nuxtjs/sentry": "^5.1.5",
"@nuxtjs/sitemap": "^2.4.0",
"@nuxtjs/svg": "^0.1.12",
@@ -5241,6 +5242,11 @@
"node": ">=12"
}
},
+ "node_modules/@nuxtjs/redirect-module": {
+ "version": "0.3.1",
+ "resolved": "https://registry.npmjs.org/@nuxtjs/redirect-module/-/redirect-module-0.3.1.tgz",
+ "integrity": "sha512-yL2unrYfUSqs+4cUtkQvEQMsuTeCOlQd+Y5sTqMZzWBadF8h01tCVDG95zmOTNIiCupb+sQho2Tixwl1f826aw=="
+ },
"node_modules/@nuxtjs/sentry": {
"version": "5.1.5",
"resolved": "https://registry.npmjs.org/@nuxtjs/sentry/-/sentry-5.1.5.tgz",
@@ -39172,6 +39178,11 @@
}
}
},
+ "@nuxtjs/redirect-module": {
+ "version": "0.3.1",
+ "resolved": "https://registry.npmjs.org/@nuxtjs/redirect-module/-/redirect-module-0.3.1.tgz",
+ "integrity": "sha512-yL2unrYfUSqs+4cUtkQvEQMsuTeCOlQd+Y5sTqMZzWBadF8h01tCVDG95zmOTNIiCupb+sQho2Tixwl1f826aw=="
+ },
"@nuxtjs/sentry": {
"version": "5.1.5",
"resolved": "https://registry.npmjs.org/@nuxtjs/sentry/-/sentry-5.1.5.tgz",
diff --git a/package.json b/package.json
index daac26658..4cab68b4f 100644
--- a/package.json
+++ b/package.json
@@ -40,6 +40,7 @@
"@nuxt/components": "^2.1.6",
"@nuxtjs/composition-api": "^0.27.0",
"@nuxtjs/i18n": "^7.0.3",
+ "@nuxtjs/redirect-module": "^0.3.1",
"@nuxtjs/sentry": "^5.1.5",
"@nuxtjs/sitemap": "^2.4.0",
"@nuxtjs/svg": "^0.1.12",
diff --git a/test/e2e/image-detail.spec.js b/test/e2e/image-detail.spec.js
index b90a62c8d..640e5a486 100644
--- a/test/e2e/image-detail.spec.js
+++ b/test/e2e/image-detail.spec.js
@@ -26,3 +26,9 @@ test('shows the main image with its title as alt text', async ({ page }) => {
test('does not show back to search results breadcrumb', async ({ page }) => {
await expect(page.locator('text="Back to search results"')).not.toBeVisible()
})
+
+test('redirects from old /photos/:id route to /image/:id', async ({ page }) => {
+ const uuid = 'e9d97a98-621b-4ec2-bf70-f47a74380452'
+ await page.goto('photos/' + uuid)
+ await expect(page).toHaveURL('image/' + uuid)
+})