Skip to content

Beautiful Open-Source Form Builder

Fix sitemap source URL without a trailing API slash (#1306)

Julien Nahumbeefe472e31e
diff --git a/client/sitemap.js b/client/sitemap.js
index f4cfc1faa..763184df7 100644
--- a/client/sitemap.js
+++ b/client/sitemap.js
@@ -14,7 +14,7 @@ export default {
'/self-hosted/checkout/**',
...(isSelfHostedBuild ? ['/self-hosted/license'] : []),
],
- sources: [`${process.env.NUXT_PUBLIC_API_BASE}sitemap-urls`],
+ sources: [`${(process.env.NUXT_PUBLIC_API_BASE || '').replace(/\/+$/, '')}/sitemap-urls`],
cacheMaxAgeSeconds: 60 * 60 * 2, // 2 hours
xslColumns: [
{ label: 'URL', width: '50%' },
diff --git a/client/test/unit/sitemap.spec.ts b/client/test/unit/sitemap.spec.ts
new file mode 100644
index 000000000..0655ec1ad
--- /dev/null
+++ b/client/test/unit/sitemap.spec.ts
@@ -0,0 +1,26 @@
+import { afterEach, describe, expect, it, vi } from 'vitest'
+
+afterEach(() => {
+ vi.unstubAllEnvs()
+ vi.resetModules()
+})
+
+describe('sitemap API source', () => {
+ it.each([
+ ['https://api.opnform.com', 'https://api.opnform.com/sitemap-urls'],
+ ['https://api.opnform.com/', 'https://api.opnform.com/sitemap-urls'],
+ ['https://forms.example.com/api', 'https://forms.example.com/api/sitemap-urls'],
+ ['https://forms.example.com/api/', 'https://forms.example.com/api/sitemap-urls'],
+ ['/api', '/api/sitemap-urls'],
+ ['/api/', '/api/sitemap-urls'],
+ ['', '/sitemap-urls'],
+ [undefined, '/sitemap-urls'],
+ ])('resolves the template source with API base %s', (base, expected) => {
+ vi.stubEnv('NUXT_PUBLIC_API_BASE', base)
+ vi.resetModules()
+
+ return import('../../sitemap.js').then(({ default: sitemap }) => {
+ expect(sitemap.sources).toEqual([expected])
+ })
+ })
+})