From 121ff48f21ac845e9e7fe0c8cb63f396a2fade62 Mon Sep 17 00:00:00 2001 From: Ben Merckx Date: Tue, 14 Nov 2023 18:08:26 +0100 Subject: [PATCH] Use defaults in preview handler --- src/core/driver/NextDriver.server.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/core/driver/NextDriver.server.tsx b/src/core/driver/NextDriver.server.tsx index b64e25327..c7bf3cd27 100644 --- a/src/core/driver/NextDriver.server.tsx +++ b/src/core/driver/NextDriver.server.tsx @@ -30,11 +30,10 @@ class NextDriver extends DefaultDriver implements NextApi { apiKey = process.env.ALINEA_API_KEY jwtSecret = this.apiKey || 'dev' - async resolver(): Promise { + async getDefaults(): Promise { const {cookies, draftMode} = await import('next/headers.js') const [draftStatus] = outcome(() => draftMode()) const isDraft = draftStatus?.isEnabled - const devUrl = process.env.ALINEA_DEV_SERVER const resolveDefaults: ResolveDefaults = { realm: Realm.Published } @@ -52,6 +51,12 @@ class NextDriver extends DefaultDriver implements NextApi { if (entryId && phase) resolveDefaults.preview = {entryId, phase, update} } } + return resolveDefaults + } + + async resolver(): Promise { + const resolveDefaults = await this.getDefaults() + const devUrl = process.env.ALINEA_DEV_SERVER if (devUrl) return new Client({ config: this.config, @@ -94,11 +99,12 @@ class NextDriver extends DefaultDriver implements NextApi { cookies().delete(PREVIEW_PHASE_NAME) } const cnx = (await this.resolver()) as Client + const resolveDefaults = await this.getDefaults() const url = (await cnx.resolve({ + ...resolveDefaults, selection: Selection.create( Entry({entryId: params.entryId}).select(Entry.url).first() - ), - realm: Realm.PreferDraft + ) })) as string | null if (!url) return new Response('Not found', {status: 404}) const source = new URL(request.url)