Skip to content

studiozeffa/threadsforslack-cf-worker

Repository files navigation

Threads for Slack worker

This is the repository for the worker functions that back the Threads for Slack app. It is built and deployed with Cloudflare Workers.

Installation

This project uses npm to manage dependencies and provide scripts for deploying the worker to Cloudflare.

Install the dependencies with:

npm install

Signup

To deploy the worker, you need a Cloudflare workers account - sign up here. The signup process will guide you through choosing a workers.dev subdomain.

Once you have signed up, you need to authenticate your local machine with your account. Do this by running

npm run wrangler login

This will save an API key to your ~/.wranger directory, and will be used automatically when deploying the worker to Cloudflare.

Configuration

The project requires a wrangler.toml file to build and deploy the worker to Cloudflare.

To get started:

  • copy the wrangler.toml.example file to wrangler.toml

You'll need to fill in the account_id value. This can be found on the Cloudflare workers dashboard:

  • Log in to your Cloudflare workers account
  • Select your worker subdomain
  • Copy the Account ID from the right hand pane, and paste it into the toml file

Deployment

During development, you can deploy the worker to Cloudflare's network and access it through localhost. This is achieved by running the command:

npm run dev

To publish the worker to production, you have 2 options.

workers.dev

Cloudflare maintains the workers.dev domain, and you can push your worker to a subdomain hosted on this network. To do this, edit the wrangler.toml file:

  • under [env.prod], set workers_dev = true

Then run the following command in the terminal

npm run publish

You can now access the worker at https://app.{your-worker-subdomain}.workers.dev.

Custom domain

If you prefer to deploy to a custom domain, follow these instructions.

Register domain

  1. If you haven't already done so, register a new domain at your favourite domain registrar. Make sure to use a registrar which supports setting custom DNS nameservers, options here include Namecheap and iwantmyname, amongst others.
  2. Log in to the main Cloudflare dashboard.
  3. In the dashboard, create a new site with your new domain name.
  4. Back in your domain registrar, change your nameservers to point to Cloudflare.

At this point, you will need to wait for the nameserver changes to propagate, which can take a few hours. You'll get an email from Cloudflare once it has detected that it is in control of the DNS for this domain - at this point, you can continue.

Configure DNS

Here, we'll set up some DNS records to point your custom domain to the Cloudflare worker.

Since Cloudflare is in control of both the DNS and the worker, the DNS records are essentially 'dummy' records, simply pointing your domain to Cloudflare's own internal network.

  1. Go to the DNS panel in your Cloudflare dashboard.
  2. Add the following records:
  • Type: A, Name: @, Content: 192.0.2.1, TTL: Auto
  • Type: AAAA, Name: @, Content: 100::, TTL: Auto

Note: if you want to deploy the worker to a subdomain, change the @ value to your subdomain - for example, to deploy to https://worker.example.com, enter the value worker in the Name field.

Configure worker

We now need to update the wrangler.toml file to deploy the worker to your new Cloudflare-managed domain. To do this:

  1. Go to the Cloudflare dashboard and select your site.
  2. Make a note of the Zone ID under the API section.
  3. In the wrangler.toml file, edit the following values under the [env.prod] section:
  • Change the zone_id value to the ones copied from the Cloudflare dashboard
  • Enter the following route: https://{your-custom-domain}/*

Deploy

You can now deploy to Cloudflare's network with

npm run publish

Check you can access your site by opening a web browser at https://{your-domain}/.

Troubleshooting

If you can't access the worker on your custom domain, your DNS cache may need to be flushed. On a mac, you can do this with the following terminal command:

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

About

No description, website, or topics provided.

Resources

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published