Subfolders
wrangler.toml files are used to define the routes for the subfolders. You can add multiple websites under subfolders on the same domain using the reverse proxy and have the main website in the root of the domain.
Understanding wrangler.toml
You can say wrangler.toml is the heart of the reverse proxy. It is used by Cloudflare workers to build the routes, connect to domains and define the behavior of the worker.
name = "NAME_OF_CLOUDFLARE_WORKER"
compatibility_date = "2024-02-07"
main ="src/index.ts"
routes = [ROUTES]
[[r2_buckets]]
binding = 'ROOT' # <~ do not change, else proxy will break
bucket_name = 'NAME_OF_CF_R2_BUCKET'
[vars]
DOMAIN = "MAIN_ENTRY_DOMAIN"
SUBDOMAINS = "SUBDOMAIN1, SUBDOMAIN2, SUBDOMAIN3"
WEBFLOW_SUBDOMAIN = "SUBDOMAIN_OF_MAIN_WEBSITE"
Here is a brief explanation of the fields in wrangler.toml:
- The
name
field is used to define the name of the Cloudflare worker. - The
bucket_name
field is used to define the name of the Cloudflare R2 bucket where we will store the files that we want to access from the root of our domain. - The
DOMAIN
field is used to define the main entry domain. This is the main domain where the worker is deployed. Thind CLI automatically creates routes for the main domain and www subdomain. - The
SUBDOMAINS
field is used to define the subdomains that you want to proxy under the main domain. Each subdomain will be accessible under the main domain using the formathttps://[maindomain.com]/[subdomain]
. Again Thind CLI automatically creates routes for the subdomains. - The
WEBFLOW_SUBDOMAIN
field is used to define the subdomain of the main website. This is the site accessible when users directly visit the main domain.
You can use npx thind@latest --setup
command to start a questionnaire that will help you generate the wrangler.toml file.
Adding Subfolders
To add a website under a subfolder, simplify adding the subdomains of the website in the SUBDOMAINS
field of the wrangler.toml file. and then run the following command:
-
Build Routes
npx thind@latest --build
This command will build the routes for the subdomains and save the updated wrangler.toml file.
-
Build Routes and Deploy
npx thind@latest proxy --deploy
This command will build the routes for the subdomains and deploy the worker to Cloudflare.