OpenNext for Cloudflare

repository·main·Indexed 23 days ago

https://github.com/opennextjs/opennextjs-cloudflare

An adapter that allows Next.js applications to be deployed to the Cloudflare Workers runtime by adapting standalone Next.js builds to work with Cloudflare's Node.js compatibility layer. It provides a CLI for building and deploying, configuration via defineCloudflareConfig, and specialized handlers for asset resolution, cache purging (including Durable Objects), and incremental caching using Cloudflare R2.

Tokens
6.6K
Snippets
13
Records
46
Agent score
83%

What's inside opennextjs-cloudflare

  1. How the blog-starter data source works

    main

    The blog-starter example demonstrates Next.js Static Generation using Markdown files.

    • Data Storage: Blog posts are stored in the /_posts directory as Markdown files.
    • Metadata: Post metadata is parsed using gray-matter and passed as props to the page.
    • Content Conversion: Markdown content is converted into HTML strings using remark and remark-html before being sent as props to the page.
    • Styling: The project uses Tailwind CSS (v3.0).
  2. How to use Next.js Middleware

    main

    Next.js Middleware allows you to run code before a request is completed. In a standard Next.js setup:

    1. Implementation: Define your logic in a middleware.ts file.
    2. Routing Control: Use a matcher in the exported config object to filter which routes the middleware runs on.
    3. Global Execution: To make the middleware run for every single request, remove the matcher from the exported config.
    4. Capabilities: Middleware can perform actions such as redirect, rewrite, or allow normal request behavior.
  3. Run end-to-end benchmarks for example applications

    main

    The benchmarking script performs full end-to-end performance testing against the example applications located in the ./examples directory. For each eligible application, the script executes the following workflow in parallel:

    1. Build: Runs the application's build:worker script.
    2. Deploy: Deploys the application to production using wrangler deploy.
    3. Identify URL: Captures the production deployment URL.
    4. Benchmark: Measures response times by performing multiple fetch requests against the deployment URL.

    Note: Certain applications may be excluded from this process based on the exampleAppsNotToBenchmark configuration found in ./src/cloudflare.ts.