Skip to content
This repository was archived by the owner on Feb 1, 2024. It is now read-only.

Standalone usage

Hunter edited this page Apr 28, 2020 · 4 revisions

This usage is for when you want to dedicate a subdomain to hosting files you put up.

Prerequisites

  • Node.js 10+ and NPM
  • Cloudflare Workers paid tier ($5/mo since KV is not available for free websites)
  • Wrangler CLI - must be logged in

Steps

  1. Clone/download this repo
  2. run npm install and npm run dist
  3. go to the kv page and create a namespace with any name you want
  4. copy .env.example to .env and fill in all of that information, along with your CF email and CF Global API key
    • CLOUDFLARE_ZONE_ID and CLOUDFLARE_ACCOUNT_ID can be obtained from the "overview" page of the domain you want to deploy to
  1. fill in CLOUDFLARE_KV_NAMESPACE_ID with that namespace ID you generated above
  2. run cross-dotenv node ./dist/cli/cli.js --path path/to/root - the --path should be the full path to the root of the domain. All files will be uploaded.
    • If you want to run the upload outside this folder, install the package globally with npm install -g cloudflare-file-hosting then use cfupload --path path/to/root. Note that all environment variables need to be set.
  1. Go to the workers tab of your domain, launch the editor, add a new script (any name you want), then click that new script
  2. copy the code from dist/worker.js into the online editor
  3. go to the "resources" tab of the script, click "add binding" for KV namespaces, enter STATIC_KV for the variable name, then select the namespace you created earlier and uploaded files to, then click save
  4. go back to the code tab then click "Save"
  5. Go to the "routes" tab of the editor, add a route for subdomain.example.com/* (the subdomain you want) pointing to this script you just created, and deploy it.

Finally, you need a DNS entry for that subdomain:

Go to the DNS tab, add a new A record with the "name" set to the subdomain you want (eg sub1.example.com would have the "name" set to sub1), then set the target to "192.0.2.1" (the reserved example IP).

Clone this wiki locally