Skip to content

Commit

Permalink
Update middleware.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
cdedreuille committed Jul 16, 2024
1 parent 67077a4 commit e29a4c3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion apps/frontpage/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { docsVersionsRedirects } from './redirects/docs-versions-redirects';
import { RedirectData } from './redirects/types';
import { docsRenderersRedirects } from './redirects/docs-renderers-redirects';
import { docsCommonRedirects } from './redirects/docs-common-redirects';
import { renderers } from '@repo/utils';

export async function middleware(request: NextRequest) {
let searchParam = request.nextUrl.searchParams.get('renderer');
Expand Down Expand Up @@ -68,8 +69,15 @@ export async function middleware(request: NextRequest) {

// If the renderer query param is set, set the cookie
const response = NextResponse.next();

if (searchParam) {
response.cookies.set(cookieRenderId, searchParam);
const findRenderer = renderers.find(
(renderer) => renderer.id === searchParam,
);

if (findRenderer) {
response.cookies.set(cookieRenderId, searchParam);
}
}

return response;
Expand Down

0 comments on commit e29a4c3

Please sign in to comment.