This is a Next.js project which uses OpenNext for Cloudflare for hosting. This project uses Tailwind CSS for styling.
Before you begin, ensure you have the following installed on your local machine:
- Node.js v22.9.0
- NVM (Node Version Manager)
-
Fork the Repository
First, fork the
structure-next-template
repository using GitHub. -
Clone the Repository to Your Local Machine Using
git
git clone YOUR_FORK
Then, initialize the Structure submodule:
cd YOUR_FORK git submodule update --init --recursive cd libraries/structure git checkout main cd ../../
-
Update package.json and Install Dependencies with
NPM
First, update the name field in
package.json
to the name of your project.Navigate into the project’s directory and install the necessary dependencies.
npm i
-
Update ProjectSettings.ts
ProjectSettings.ts
is used to configure all of your project settings. Update the file with your project-specific information. -
Update wrangler.toml
wrangler.toml
is used to configure your deployment to Cloudflare. You will need to review each line in this file and update it for your project. -
Update the Assets Hostname in
next.config.mjs
The project assumes you will be using a service like Cloudflare R2 to store images. Next.JS needs to be configured to not to optimize images from that host.
-
(If Using Base API) Update Your package.json Scripts and System hosts File
Update Your package.json Scripts
By default, the development server will run on port 7878 over regular
HTTP
, notHTTPs
. If you are using the Base API, it will requireHTTP Only
cookies in order for the account system to work. These cookies are secure and are not accessible via JavaScript. These cookies will only be sent by web browsers withHTTPS
connections. So,HTTPS
needs to be enabled in your development environment.Replace the dev script in your package.json:
// Default "dev": "next dev --port 7878", // Update to: "dev": "next dev --experimental-https --port 7878 --hostname localhost.PROJECT_DOMAIN.TLD",
Where
PROJECT_DOMAIN.TLD
is the domain where you will host your project.Update Your System hosts File
In order to access your
HTTPS
web server hosted onlocalhost.PROJECT_DOMAIN.TLD
, you will need to update your system hosts file:sudo nano /etc/hosts
Add this line:
127.0.0.1 localhost.PROJECT_DOMAIN.TLD
Now
localhost.PROJECT_DOMAIN.TLD
will point to your local machine. -
Start the Development Server
Start the development server using:
npm run dev
You will be prompted to generate keys necessary to enable
HTTPS
for local development. After the server is running, open https://localhost.PROJECT_DOMAIN.TLD:7878 with your browser.You can now view the website in your web browser. Please note that any changes you make in your local codebase will automatically be reflected on your local server.
To synchronize your GraphQL types with the Base API, use:
npm run api
This command expects the api
git repository to be in the api
folder in the same directory as your website
git repository.
npm run build
to build the applicationnpm run preview
to locally preview your application using the Wrangler CLInpm run deploy
to deploy your application using the Wrangler CLI
Note: While the
npm run dev
script is optimal for local development you should usenpm run preview
on your application as well (periodically or before deployments) in order to make sure that it can properly work in the Cloudflare environment
In this project, we are utilizing Next.js App Router
. The App Router
determines routing based on the structure of the /app
directory.
This project uses Tailwind CSS, a utility-first CSS framework, for styling. The configuration file for Tailwind CSS is tailwind.config.js
. As part of the development process, you may need to customize this file according to your feature needs.
The following resources may help you familiarize yourself with the technologies used in this project:
Happy coding!