Skip to content

The open alternative to Salesforce, designed for AI.

Fix frontend routing for dotted navigation paths (#26711)

Félix Malfait175a90123802
diff --git a/packages/twenty-server/src/engine/core-modules/frontend/__tests__/frontend.service.spec.ts b/packages/twenty-server/src/engine/core-modules/frontend/__tests__/frontend.service.spec.ts
index 13e41209cb9..517a03d0be8 100644
--- a/packages/twenty-server/src/engine/core-modules/frontend/__tests__/frontend.service.spec.ts
+++ b/packages/twenty-server/src/engine/core-modules/frontend/__tests__/frontend.service.spec.ts
@@ -227,7 +227,6 @@ describe('frontend HTML delivery', () => {
'/graphql/missing',
'/rest/missing',
'/auth/missing',
- '/assets/missing.js',
'/.well-known/missing',
])('does not turn %s into a successful HTML response', async (pathname) => {
await request(app.getHttpServer())
@@ -274,6 +273,31 @@ describe('frontend HTML delivery', () => {
},
);
+ it.each([
+ '/invite/apple.dev-invite-hash',
+ '/invite/apple.dev-invite-hash/',
+ '/settings/domains/crm.example.com',
+ ])('serves browser navigation to dotted path %s', async (pathname) => {
+ await request(app.getHttpServer())
+ .get(pathname)
+ .set('Accept', 'text/html,application/xhtml+xml,*/*;q=0.8')
+ .set('Sec-Fetch-Dest', 'document')
+ .expect(200);
+ expect(getClientConfig).toHaveBeenCalledTimes(1);
+ });
+
+ it.each(['script', 'style', 'empty'])(
+ 'does not serve a document for a missing asset with Sec-Fetch-Dest: %s',
+ async (destination) => {
+ await request(app.getHttpServer())
+ .get('/assets/missing.js')
+ .set('Accept', 'text/html')
+ .set('Sec-Fetch-Dest', destination)
+ .expect(404);
+ expect(getClientConfig).not.toHaveBeenCalled();
+ },
+ );
+
it('serves extensionless static files in arbitrary directories before the SPA fallback', async () => {
mkdirSync(join(directory, 'new-asset-directory'));
writeFileSync(
diff --git a/packages/twenty-server/src/engine/core-modules/frontend/utils/is-frontend-document-request.util.ts b/packages/twenty-server/src/engine/core-modules/frontend/utils/is-frontend-document-request.util.ts
index 6e8fb89ad5c..337f318c819 100644
--- a/packages/twenty-server/src/engine/core-modules/frontend/utils/is-frontend-document-request.util.ts
+++ b/packages/twenty-server/src/engine/core-modules/frontend/utils/is-frontend-document-request.util.ts
@@ -1,9 +1,9 @@
-import { extname } from 'path';
-
import { type Request } from 'express';
import { isDefined } from 'twenty-shared/utils';
import { ApiPath } from 'twenty-shared/types';
+const NAVIGATION_DESTINATIONS = ['document', 'iframe', 'frame'];
+
export const isFrontendDocumentRequest = (request: Request): boolean => {
if (request.method !== 'GET' && request.method !== 'HEAD') {
return false;
@@ -18,9 +18,7 @@ export const isFrontendDocumentRequest = (request: Request): boolean => {
return (
!isApiPath &&
- (pathname === '/index.html' || extname(pathname) === '') &&
request.accepts().includes('text/html') &&
- (!isDefined(destination) ||
- ['document', 'iframe', 'frame'].includes(destination))
+ (!isDefined(destination) || NAVIGATION_DESTINATIONS.includes(destination))
);
};