From b58c991c814bd27eb7d87e5aa6bcb4ccbd0f2665 Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Thu, 10 Apr 2025 22:54:59 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(nginx)=20fix=20404=20when=20access?= =?UTF-8?q?ing=20a=20doc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We improve the nginx way to access to a specific doc. We stop to wait for a initial attempt that give a 404. If we see a UUID in the url we will redirect to the doc/[id] page. Next will then manage the 404. --- CHANGELOG.md | 4 ++++ .../e2e/__tests__/app-impress/doc-routing.spec.ts | 7 +++++-- .../apps/e2e/__tests__/app-impress/language.spec.ts | 11 ++--------- src/frontend/apps/impress/conf/default.conf | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4f54fa0..af0f381f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,10 @@ and this project adheres to ⚡️(frontend) reduce unblocking time for config #867 +## Fixed + +- 🐛(nginx) fix 404 when accessing a doc #866 + ## [3.1.0] - 2025-04-07 ## Added diff --git a/src/frontend/apps/e2e/__tests__/app-impress/doc-routing.spec.ts b/src/frontend/apps/e2e/__tests__/app-impress/doc-routing.spec.ts index 95019784..9aebb408 100644 --- a/src/frontend/apps/e2e/__tests__/app-impress/doc-routing.spec.ts +++ b/src/frontend/apps/e2e/__tests__/app-impress/doc-routing.spec.ts @@ -1,3 +1,5 @@ +import crypto from 'crypto'; + import { expect, test } from '@playwright/test'; import { @@ -101,8 +103,9 @@ test.describe('Doc Routing: Not loggued', () => { page, browserName, }) => { - await mockedDocument(page, { link_reach: 'public' }); - await page.goto('/docs/mocked-document-id/'); + const uuid = crypto.randomUUID(); + await mockedDocument(page, { link_reach: 'public', id: uuid }); + await page.goto(`/docs/${uuid}/`); await expect(page.locator('h2').getByText('Mocked document')).toBeVisible(); await page.getByRole('button', { name: 'Login' }).click(); await keyCloakSignIn(page, browserName, false); diff --git a/src/frontend/apps/e2e/__tests__/app-impress/language.spec.ts b/src/frontend/apps/e2e/__tests__/app-impress/language.spec.ts index 58f3646c..5805d010 100644 --- a/src/frontend/apps/e2e/__tests__/app-impress/language.spec.ts +++ b/src/frontend/apps/e2e/__tests__/app-impress/language.spec.ts @@ -54,18 +54,11 @@ test.describe.serial('Language', () => { }) => { // Helper function to intercept and assert 404 response const check404Response = async (expectedDetail: string) => { - const expectedBackendResponse = page.waitForResponse( - (response) => - response.url().includes('/api') && - response.url().includes('non-existent-doc-uuid') && - response.status() === 404, + const interceptedBackendResponse = await page.request.get( + 'http://localhost:8071/api/v1.0/documents/non-existent-doc-uuid/', ); - // Trigger the specific 404 XHR response by navigating to a non-existent document - await page.goto('/docs/non-existent-doc-uuid'); - // Assert that the intercepted error message is in the expected language - const interceptedBackendResponse = await expectedBackendResponse; expect(await interceptedBackendResponse.json()).toStrictEqual({ detail: expectedDetail, }); diff --git a/src/frontend/apps/impress/conf/default.conf b/src/frontend/apps/impress/conf/default.conf index 5007b3f3..5fe19bc4 100644 --- a/src/frontend/apps/impress/conf/default.conf +++ b/src/frontend/apps/impress/conf/default.conf @@ -9,8 +9,8 @@ server { try_files $uri index.html $uri/ =404; } - location /docs/ { - error_page 404 /docs/[id]/; + location ~ "^/docs/[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/?$" { + try_files $uri /docs/[id]/index.html; } error_page 404 /404.html;