Skip to content

Commit

Permalink
Fix deploy instructions in README, remove dotenv-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
benvinegar committed Jan 1, 2024
1 parent 36fe42b commit a60db70
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 55 deletions.
47 changes: 21 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,32 @@ It's designed to be easy to deploy and maintain, and should cost you near-zero t

_NOTE: Counterscale is currently in very early development and if you're prepared to run it, expect to get your hands dirty._

## Prerequisites

You need a Cloudflare account, and have enabled [Cloudflare Analytics Engine beta](https://developers.cloudflare.com/analytics/analytics-engine/get-started/).
## Deployment

## Configuration
If you don't have one already, [create a Cloudflare account here](https://dash.cloudflare.com/sign-up).

1. Go to your Cloudflare dashboard and set up a Cloudflare Workers subdomain
1. Enable [Cloudflare Analytics Engine beta](https://developers.cloudflare.com/analytics/analytics-engine/get-started/) for your account
1. Create a [Cloudflare API token](https://developers.cloudflare.com/fundamentals/api/get-started/create-token/). This token needs `Account.Account Analytics` permissions at a minimum.
1. Run `npm install`
1. Run `npx wrangler secret put CF_BEARER_TOKEN` → when prompted, paste the API token you created
1. Run `npx wrangler secret put CF_ACCOUNT_ID` → when prompted, paste your Cloudflare Account ID
1. Run `npm run deploy` – this will do two things:
1. Create a new worker, `counterscale`, now visible under *Workers and Pages* in Cloudflare
1. Create a new Analytics Engine dataset, called `metricsDataset`
1. `CF_BEARER_TOKEN` → the API token you created
1. `CF_ACCOUNT_ID` → your Cloudflare Account ID
1. It should now be live. Visit `https://counterscale.{yoursubdomain}.workers.dev`.

You need to create a [Clouflare API token](https://developers.cloudflare.com/fundamentals/api/get-started/create-token/). This token needs `Account.Account Analytics` permissions.
## Development

Once you have the token, and your Cloudflare account ID, you need to:
### Config

1. Copy `.dev.vars.example` to `.dev.vars`
2. Add `CF_BEARER_TOKEN` (this is your API token)
3. Add `CF_ACCOUNT_ID` (this is your Cloudflare account ID)
4. Open up the Cloudflare Dashboard (web), and add both values as environment variables
To get started, in the project root, copy `.dev.vars.example` to `.dev.vars`.

## Development
Open `.dev.vars` and enter the same values for `CF_BEARER_TOKEN` and `CF_ACCOUNT_ID` you used earlier.

Install dependencies using `npm`:

```sh
npm install
```
### Running the Server

Counterscale is built on Remix and Cloudflare Workers. In development, you'll run two servers:

Expand Down Expand Up @@ -63,13 +67,4 @@ Right now there is no local "test" database. This means in local development:

* Writes will no-op (no hits will be recorded)
* Reads will be read from the production Analaytics Engine dataset (local development shows production data)

## Deployment

If you don't already have an account, then [create a cloudflare account here](https://dash.cloudflare.com/sign-up) and after verifying your email address with Cloudflare, go to your dashboard and set up your free custom Cloudflare Workers subdomain.

Once that's done, you should be able to deploy your app:

```sh
npm run deploy
```

25 changes: 0 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"type": "module",
"scripts": {
"build": "remix build",
"_deploy": "wrangler deploy --name $CF_APP_NAME",
"deploy": "dotenv -e .dev.vars -- npm run _deploy",
"deploy": "wrangler deploy",
"dev": "remix dev --manual -c \"npm start\"",
"lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .",
"start": "wrangler dev ./build/index.js",
Expand Down Expand Up @@ -39,7 +38,6 @@
"@types/ua-parser-js": "^0.7.39",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"autoprefixer": "^10.4.16",
"dotenv-cli": "^7.3.0",
"eslint": "^8.38.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-typescript": "^3.6.1",
Expand Down
5 changes: 4 additions & 1 deletion wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# default deploy name
name = "counterscale"

workers_dev = true
main = "./build/index.js"
# https://developers.cloudflare.com/workers/platform/compatibility-dates
Expand All @@ -10,5 +13,5 @@ compatibility_date = "2023-04-20"
command = "npm run build"

[[analytics_engine_datasets]]
binding = "WEB_COUNTER_DS"
binding = "WEB_COUNTER_AE"
dataset = "metricsDataset"

0 comments on commit a60db70

Please sign in to comment.