Skip to content

Conversation

@ben-fornefeld
Copy link
Member

@ben-fornefeld ben-fornefeld commented Apr 4, 2025

After #18 we were using NextResponse.rewrite to rewrite our content pages inside middleware.ts. The exact reasons are unclear but this had some massive latency overhead on every rewritten route which was not ideal. This pr adds a catch-all route handler which catches all paths that are not defined by the next router. Here we do our content page rewrites & add cache policies to the fetches & responses with revalidation after 15 minutes. Since we use a catch-all handler, we need to manually handle our root 404 page as well. Returning nextjs's notFound() did only send a 404 status to the browser, but we want to render our custom not-found page. Hence I added a new route just holding our not-found component and rewrite accordingly in the catch-all handler.

This results in much faster performance of our content pages & separates the rewriting process from the middlewares business logic for clearer separation of concerns.

@ben-fornefeld ben-fornefeld added the enhancement New feature or request label Apr 4, 2025
@ben-fornefeld ben-fornefeld self-assigned this Apr 4, 2025
@linear
Copy link

linear bot commented Apr 4, 2025

@vercel
Copy link

vercel bot commented Apr 4, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 4, 2025 11:44pm
web-juliett ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 4, 2025 11:44pm

@ben-fornefeld ben-fornefeld marked this pull request as draft April 4, 2025 23:33
Copy link
Member

@ValentaTomas ValentaTomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me—we went over the details together.

@ben-fornefeld ben-fornefeld requested a review from jakubno April 5, 2025 00:07
@ben-fornefeld ben-fornefeld merged commit 0bd5855 into main Apr 5, 2025
4 checks passed
@ben-fornefeld ben-fornefeld deleted the improve-latency-for-landing-page-rewrites-e2b-1892 branch April 5, 2025 00:08
ben-fornefeld added a commit that referenced this pull request Apr 6, 2025
#34 introduced a catch-all route handler that acts as a fallback
rewriter for our content pages. It had implementations of caching
mechanisms, but these did not seem to work as expected in production.

This pr introduces the use of `generateStaticParams` to cache route
invocations for the paths present in our `sitemap` on build time, which
results in instant server responses on our rewritten pages.
kitchenbeats pushed a commit to kitchenbeats/botlink-dashboard that referenced this pull request Oct 20, 2025
kitchenbeats pushed a commit to kitchenbeats/botlink-dashboard that referenced this pull request Oct 20, 2025
e2b-dev#34 introduced a catch-all route handler that acts as a fallback
rewriter for our content pages. It had implementations of caching
mechanisms, but these did not seem to work as expected in production.

This pr introduces the use of `generateStaticParams` to cache route
invocations for the paths present in our `sitemap` on build time, which
results in instant server responses on our rewritten pages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants