Giter Site home page Giter Site logo

fullstack-cf-pages-next-app's Introduction

This is a Next.js project bootstrapped with c3.

Getting Started

First, run the development server:

npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev

Open http://localhost:3000 with your browser to see the result.

Cloudflare integration

Besides the dev script mentioned above c3 has added a few extra scripts that allow you to integrate the application with the Cloudflare Pages environment, these are:

  • pages:build to build the application for Pages using the @cloudflare/next-on-pages CLI
  • preview to locally preview your Pages application using the Wrangler CLI
  • deploy to deploy your Pages application using the Wrangler CLI

Note: while the dev script is optimal for local development you should preview your Pages application as well (periodically or before deployments) in order to make sure that it can properly work in the Pages environment (for more details see the @cloudflare/next-on-pages recommended workflow)

Bindings

Cloudflare Bindings are what allows you to interact with resources available in the Cloudflare Platform.

You can use bindings during development, when previewing locally your application and of course in the deployed application:

  • To use bindings in dev mode you need to define them in the next.config.js file under setupDevBindings, this mode uses the next-dev @cloudflare/next-on-pages submodule. For more details see its documentation.

  • To use bindings in the preview mode you need to add them to the pages:preview script accordingly to the wrangler pages dev command. For more details see its documentation or the Pages Bindings documentation.

  • To use bindings in the deployed application you will need to configure them in the Cloudflare dashboard. For more details see the Pages Bindings documentation.

KV Example

c3 has added for you an example showing how you can use a KV binding.

In order to enable the example:

  • Search for javascript/typescript lines containing the following comment:
    // KV Example:
    and uncomment the commented lines below it.
  • Do the same in the wrangler.toml file, where the comment is:
    # KV Example:
    
  • If you're using TypeScript run the cf-typegen script to update the env.d.ts file:
    npm run cf-typegen
    # or
    yarn cf-typegen
    # or
    pnpm cf-typegen
    # or
    bun cf-typegen

After doing this you can run the dev or preview script and visit the /api/hello route to see the example in action.

Finally, if you also want to see the example work in the deployed application make sure to add a MY_KV_NAMESPACE binding to your Pages application in its dashboard kv bindings settings section. After having configured it make sure to re-deploy your application.

fullstack-cf-pages-next-app's People

Contributors

chiubaca avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.