This repository was archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
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.
- 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
- Clone/download this repo
- run
npm install
andnpm run dist
- go to the kv page and create a namespace with any name you want
- 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
- CLOUDFLARE_ZONE_ID and CLOUDFLARE_ACCOUNT_ID can be obtained from the "overview" page of the domain you want to deploy to
- fill in CLOUDFLARE_KV_NAMESPACE_ID with that namespace ID you generated above
- 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 usecfupload --path path/to/root
. Note that all environment variables need to be set.
- If you want to run the upload outside this folder, install the package globally with
- Go to the workers tab of your domain, launch the editor, add a new script (any name you want), then click that new script
- copy the code from
dist/worker.js
into the online editor - 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
- go back to the code tab then click "Save"
- 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).