Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ jobs:
- plugin-redirects
- plugin-seo
- sort
- server-url
- trash
- versions
- uploads
Expand Down
4 changes: 3 additions & 1 deletion packages/next/src/views/NotFound/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const NotFoundPage = async ({

const searchParams = await searchParamsPromise
const queryString = `${qs.stringify(searchParams ?? {}, { addQueryPrefix: true })}`

const {
locale,
permissions,
Expand All @@ -65,7 +66,8 @@ export const NotFoundPage = async ({
ignoreQueryPrefix: true,
}),
},
urlSuffix: `${formatAdminURL({ adminRoute, path: '/not-found', serverURL: config.serverURL })}${searchParams ? queryString : ''}`,
// intentionally omit `serverURL` to keep URL relative
urlSuffix: `${formatAdminURL({ adminRoute, path: '/not-found' })}${searchParams ? queryString : ''}`,
},
})

Expand Down
7 changes: 6 additions & 1 deletion packages/next/src/views/Root/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export const RootPage = async ({
}

const queryString = `${qs.stringify(searchParams ?? {}, { addQueryPrefix: true })}`

const {
cookies,
locale,
Expand All @@ -138,7 +139,11 @@ export const RootPage = async ({
ignoreQueryPrefix: true,
}),
},
urlSuffix: `${currentRoute}${searchParams ? queryString : ''}`,
// intentionally omit `serverURL` to keep URL relative
urlSuffix: `${formatAdminURL({
adminRoute,
path: Array.isArray(params.segments) ? `/${params.segments.join('/')}` : null,
})}${searchParams ? queryString : ''}`,
},
})

Expand Down
2 changes: 2 additions & 0 deletions test/server-url/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/media
/media-gif
31 changes: 31 additions & 0 deletions test/server-url/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { lexicalEditor } from '@payloadcms/richtext-lexical'
import { fileURLToPath } from 'node:url'
import path from 'path'

import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
import { devUser } from '../credentials.js'

const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)

export default buildConfigWithDefaults({
serverURL: 'http://localhost:3000',
admin: {
importMap: {
baseDir: path.resolve(dirname),
},
},
editor: lexicalEditor({}),
onInit: async (payload) => {
await payload.create({
collection: 'users',
data: {
email: devUser.email,
password: devUser.password,
},
})
},
typescript: {
outputFile: path.resolve(dirname, 'payload-types.ts'),
},
})
35 changes: 35 additions & 0 deletions test/server-url/e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { Page } from '@playwright/test'

import { expect, test } from '@playwright/test'
import * as path from 'path'
import { fileURLToPath } from 'url'

import { ensureCompilationIsDone, initPageConsoleErrorCatch } from '../helpers.js'
import { AdminUrlUtil } from '../helpers/adminUrlUtil.js'
import { initPayloadE2ENoConfig } from '../helpers/initPayloadE2ENoConfig.js'
import { TEST_TIMEOUT_LONG } from '../playwright.config.js'

const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)

test.describe('serverURL', () => {
let page: Page
let url: AdminUrlUtil

test.beforeAll(async ({ browser }, testInfo) => {
testInfo.setTimeout(TEST_TIMEOUT_LONG)

const { payload, serverURL } = await initPayloadE2ENoConfig({ dirname })
url = new AdminUrlUtil(serverURL, 'posts')

const context = await browser.newContext()
page = await context.newPage()
initPageConsoleErrorCatch(page)
await ensureCompilationIsDone({ page, serverURL })
})

test('can load admin panel when serverURL is set', async () => {
await page.goto(url.admin)
await expect(page.getByText('Dashboard')).toBeVisible()
})
})
Loading
Loading