Skip to main content

Cloudflare Static Website

The Cloudflare Static Website template scaffolds a Pulumi project that serves your site’s files as static assets from a Cloudflare Worker, exposed on its own workers.dev subdomain. Pulumi uploads the contents of the site folder as a versioned set of Worker assets and rolls that version out to all of the Worker’s traffic with a Workers deployment. The template ships with placeholder web content so the project deploys end to end out of the box.

Architecture diagram of the Cloudflare Static Website template Cloudflare Cloudflare Worker Static Assets

Using this template#

To use this template to deploy a website of your own, make sure you’ve installed Pulumi and configured your Cloudflare credentials, then create a new project using the template in the language of your choice:

Terminal window
mkdir my-site && cd my-site
pulumi new static-website-cloudflare-typescript

Follow the prompts to complete the new-project wizard. When it’s done, you’ll have a complete Pulumi project that’s ready to deploy and configured with the most common settings. Feel free to inspect the code in index.ts for a closer look.

Deploying the project#

The template needs one setting to deploy: the Cloudflare account ID to deploy into. Set it, then deploy with pulumi up:

Terminal window
pulumi config set accountId <your-account-id>
pulumi up

When the deployment completes, Pulumi exports the following stack output value:

url

The fully-qualified HTTPS URL of the deployed website on its workers.dev subdomain.

Output values like this one are useful in many ways, most commonly as inputs for other stacks or related cloud resources. The computed URL, for example, can be used from the command line to open the newly deployed website in your favorite web browser:

Terminal window
open $(pulumi stack output url)

Customizing the project#

Projects created with the Static Website template expose the following configuration settings:

path

The path to the folder containing the files of the website. Defaults to ./www, which is the relative path of the folder included with the template.

This setting is optional and may be adjusted either by editing the stack configuration file directly (by default, Pulumi.dev.yaml) or by changing its value with pulumi config set.

Using your own web content#

If you already have a static website you’d like to deploy on Cloudflare with Pulumi, you can do so either by replacing the placeholder content in the www folder or by configuring the stack to point to another folder on your computer with the path setting:

Terminal window
pulumi config set path ../my-existing-website/build
pulumi up

Cleaning up#

You can cleanly destroy the stack and all of its infrastructure with pulumi destroy:

Terminal window
pulumi destroy

Learn more#

Related

The infrastructure as code platform for any cloud.