Analog
Analog is a fullstack meta-framework for Angular, powered by Vite and Nitro.
In this guide, you will create a new Analog application and deploy it using Cloudflare Pages.
The easiest way to create a new Analog project and deploy to Cloudflare Pages is to use the create-cloudflare
CLI (also known as C3). To get started, open a terminal and run:
C3 will walk you through the setup process and create a new project using create-analog
, the official Analog creation tool. It will also install the necessary adapters along with the Wrangler CLI.
A binding allows your application to interact with Cloudflare developer products, such as KV, Durable Objects, R2, and D1.
If you intend to use bindings in your project, you must first set up your bindings for local and remote development.
In Analog, server-side code can be added via API Routes. The defineEventHandler()
method is used to define your API endpoints in which you can access Cloudflare’s context via the provided context
field. The context
field allows you to access any bindings set for your application.
The following code block shows an example of accessing a KV namespace in Analog.
Projects created via C3 come installed with a Nitro module that simplifies the process of working with bindings during development:
This module in turn loads a plugin which adds bindings to the event context in dev:
In the code above, the getPlatformProxy
helper function will automatically detect any bindings defined in your project’s wrangler.toml
file and emulate those bindings in local development. Review Wrangler configuration information on bindings for more information on how to configure bindings in wrangler.toml
.
A new type definition for the Env
type (used by context.cloudflare.env
) can be generated from wrangler.toml
with the following command:
This should be done any time you add new bindings to wrangler.toml
.
In order to access bindings in a deployed application, you will need to configure your bindings in the Cloudflare dashboard.
When creating your new project, C3 will give you the option of deploying an initial version of your application via Direct Upload. You can redeploy your application at any time by running following command inside your project directory:
In addition to Direct Upload deployments, you can deploy projects via Git integration. Git integration allows you to connect a GitHub or GitLab repository to your Pages application and have your Pages application automatically built and deployed after each new commit is pushed to it.
Setup requires a basic understanding of Git. If you are new to Git, refer to GitHub’s summarized Git handbook on how to set up Git on your local machine.
Create a new GitHub repository by visiting repo.new. After creating a new repository, go to your newly created project directory to prepare and push your local application to GitHub by running the following commands in your terminal:
- Log in to the Cloudflare dashboard and select your account.
- Go to Workers & Pages > Create application > Pages > Connect to Git and create a new Pages project.
You will be asked to authorize access to your GitHub account if you have not already done so. Cloudflare needs this so that it can monitor and deploy your projects from the source. You may narrow access to specific repositories if you prefer; however, you will have to manually update this list within your GitHub settings when you want to add more repositories to Cloudflare Pages.
- Select the new GitHub repository that you created and, in the Set up builds and deployments section, provide the following information:
Configuration option | Value |
---|---|
Production branch | main |
Build command | npm run build |
Build directory | dist/analog/public |
Optionally, you can customize the Project name field. It defaults to the GitHub repository’s name, but it does not need to match. The Project name value is assigned as your *.pages.dev
subdomain.
- After completing configuration, select the Save and Deploy.
Review your first deploy pipeline in progress. Pages installs all dependencies and builds the project as specified. Cloudflare Pages will automatically rebuild your project and deploy it on every new pushed commit.
Additionally, you will have access to preview deployments, which repeat the build-and-deploy process for pull requests. With these, you can preview changes to your project with a real URL before deploying your changes to production.