Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cloudflare.md #15

Merged
merged 10 commits into from
Dec 28, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions deploy/cloudflare.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,38 @@ outline: deep

Uploading via Web UI is limited to 300 MB.

Use [rclone](https://rclone.org/downloads/) to upload larger PMTiles archives to R2.
Use [rclone](https://rclone.org/downloads/) to upload larger PMTiles archives to R2 (you can use the `rclone/rclone` docker image in order to avoid installation, the config is at `/etc/rclone` for mounting).
In order to use rclone you'll need to create an API key. Copy the "Access Key ID", the "Secret Access Key" and the "Endpoints for S3 clients" from the API key creation screen.
Run the following commands:
1. `rclone config` and follow the on screen questions, note that the endpoint should be `https://<ACCOUNT_ID>.r2.cloudflarestorage.com/<BUCKET_NAME>`
2. `rclone copy your.pmtiles <the name you gave the above rclone configuration):<FOLDER_INSIDE_THE_BEUCKET> to upload the file

Name your uploads to storage with the `.pmtiles` extension. Your tile requests to the Workers URL will look like `/FILENAME/0/0/0.ext` for the archive `FILENAME.pmtiles`.

### 2. Create Worker with Web Console

1. In the Workers tab of the Cloudflare dashboard, choose **Create a Service**.
1. In the Workers left menu of the Cloudflare dashboard, choose **Create Worker**.

2. Leave the default **HTTP handler** option.
2. It will ask you to deploy it first before you can edit the code, click **Deploy**

3. in Settings for your worker, choose Variables > R2 Bucket Bindings > **Add Binding**.
3. Paste in this code from: [index.js](https://protomaps.github.io/PMTiles/index.js).

* Create variable with name `BUCKET` and select your R2 bucket from Step 1.
4. Leave the default **HTTP handler** option.

* Choose **Save and Deploy**.
5. Choose **Save and Deploy** and leave the code editing window.

6. Select the newly create worker from the workers list

4. in **Quick Edit**, paste in this code: [index.js](https://protomaps.github.io/PMTiles/index.js).
7. In Settings of your worker, choose Variables > R2 Bucket Bindings > **Add Binding**.

* Create variable with name `BUCKET` and select your R2 bucket from Step 1.

* Choose **Save and Deploy**.


Your worker should now be active at its `*.workers.dev` domain.

Make a request for `/FILENAME/0/0/0.EXT` to verify tiles are served.
Make a request for `<ACCOUNT_NAME>.workers.dev/<FOLDER>/<FILENAME>/0/0/0.<mvt | pbf | png>` to verify tiles are served.

### Alternative: Use Wrangler

Expand Down Expand Up @@ -96,4 +105,4 @@ Optional environment variables can be set set in `[vars]` of `wrangler.toml` or

## Cache Invalidation

* For Cloudflare, "Purge Cache" applies to all cached resources in the zone (domain). It's recommended to deploy on a dedicated zone for this reason.
* For Cloudflare, "Purge Cache" applies to all cached resources in the zone (domain). It's recommended to deploy on a dedicated zone for this reason.