Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo Site: don't exclude middleware for /api/... requests #3086

Merged
merged 2 commits into from
Jan 14, 2025
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
2 changes: 1 addition & 1 deletion demo/admin/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class App extends Component {
siteConfig.scope.domain === "secondary"
? `${siteConfig.url}/block-preview`
: `${siteConfig.url}/block-preview/${scope.domain}/${scope.language}`,
sitePreviewApiUrl: `${siteConfig.url}/api/site-preview`,
sitePreviewApiUrl: `${siteConfig.url}/site-preview`,
};
},
}}
Expand Down
7 changes: 3 additions & 4 deletions demo/site/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { withAdminRedirectMiddleware } from "./middleware/adminRedirect";
import { withBlockPreviewMiddleware } from "./middleware/blockPreview";
import { chain } from "./middleware/chain";
import { withCspHeadersMiddleware } from "./middleware/cspHeaders";
import { withDamRewriteMiddleware } from "./middleware/damRewrite";
import { withDomainRewriteMiddleware } from "./middleware/domainRewrite";
import { withPredefinedPagesMiddleware } from "./middleware/predefinedPages";
import { withPreviewMiddleware } from "./middleware/preview";
import { withRedirectToMainHostMiddleware } from "./middleware/redirectToMainHost";
import { withSitePreviewMiddleware } from "./middleware/sitePreview";

Expand All @@ -14,7 +14,7 @@ export default chain([
withAdminRedirectMiddleware,
withDamRewriteMiddleware,
withCspHeadersMiddleware, // order matters: after redirects (that don't need csp headers), before everything else that needs csp headers
withBlockPreviewMiddleware,
withPreviewMiddleware,
withPredefinedPagesMiddleware,
withDomainRewriteMiddleware, // must be last (rewrites all urls)
]);
Expand All @@ -23,14 +23,13 @@ export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - api (API routes)
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico, favicon.svg, favicon.png
* - manifest.json
* - robots.txt
*/
"/((?!api|_next/static|_next/image|favicon.ico|favicon.svg|favicon.png|manifest.json|robots.txt).*)",
"/((?!_next/static|_next/image|favicon.ico|favicon.svg|favicon.png|manifest.json|robots.txt).*)",
],
// TODO find a better solution for this (https://nextjs.org/docs/messages/edge-dynamic-code-evaluation)
unstable_allowDynamic: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { NextRequest, NextResponse } from "next/server";

import { CustomMiddleware } from "./chain";

export function withBlockPreviewMiddleware(middleware: CustomMiddleware) {
export function withPreviewMiddleware(middleware: CustomMiddleware) {
return async (request: NextRequest) => {
if (request.nextUrl.pathname.startsWith("/block-preview/")) {
if (request.nextUrl.pathname.startsWith("/block-preview/") || request.nextUrl.pathname.startsWith("/site-preview/")) {
// don't apply any other middlewares
return NextResponse.next();
}
Expand Down
Loading