Skip to content

Commit

Permalink
fix: use x-makeswift-draft-mode header for proxy
Browse files Browse the repository at this point in the history
The URL search param is only set on the very first request. For the
proxy to work as intended, the `x-makeswift-draft-mode` header must be
used to determine whether to proxy Draft Mode or not.
  • Loading branch information
migueloller committed Feb 1, 2025
1 parent 997fa53 commit ab6368e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/middlewares/with-makeswift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { MiddlewareFactory } from './compose-middlewares';

export const withMakeswift: MiddlewareFactory = (middleware) => {
return async (request, event) => {
const apiKey = request.nextUrl.searchParams.get('x-makeswift-draft-mode');
const apiKey =
request.nextUrl.searchParams.get('x-makeswift-draft-mode') ??
request.headers.get('x-makeswift-draft-mode');

if (apiKey === process.env.MAKESWIFT_SITE_API_KEY) {
const response = await fetch(new URL('/api/makeswift/draft-mode', request.nextUrl.origin), {
Expand Down

0 comments on commit ab6368e

Please sign in to comment.