Skip to content

Commit

Permalink
Update Workers example
Browse files Browse the repository at this point in the history
  • Loading branch information
jahands committed Nov 6, 2023
1 parent 115a7b1 commit 6e458fc
Show file tree
Hide file tree
Showing 11 changed files with 1,336 additions and 3,690 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# http://editorconfig.org
root = true

[*]
indent_style = tab
tab_width = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yml]
indent_style = space
96 changes: 82 additions & 14 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,104 +1,172 @@
# Logs

logs
*.log
npm-debug.log*
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
*.pid
*.seed
*.pid.lock
_.pid
_.seed
\*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
*.lcov
\*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/
# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache
*.tsbuildinfo

\*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'
*.tgz

\*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variables file
# dotenv environment variable files

.env
.env.test
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.cache
.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js

# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp
.cache

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.\*

# wrangler project

.dev.vars
.wrangler/
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 140,
"singleQuote": true,
"semi": false,
"useTabs": true
}
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,25 @@ This worker script can send logs from Cloudflare to Axiom.

## Quickstart

Copy the contents of `src/worker.js` into a new worker on cloudflare

Update the authentication variables to corresponding dataset and token:
```ts
const axiomDataset = "my-dataset" // Your Axiom dataset
const axiomToken = "xapt-xxx" // Your Axiom API token
- Create a new Workers application: `npm create cloudflare@latest`
- Select `"Hello World" Worker`
- Select `yes` when prompted to use TypeScript
- Replace the contents of `src/index.ts` with the contents of `src/index.ts` from this repository
- Copy `src/axiom.ts` from this repository into your project
- Update the AxiomLogger constructor in `src/index.ts` with your dataset and token:
- Upload your Axiom token as a [Workers secret](https://developers.cloudflare.com/workers/configuration/secrets/): `npx wrangler secret put AXIOM_TOKEN`

Update the dataset in `src/index.ts` with Axiom your dataset name:

```typescript
const logger = new AxiomLogger({
...
dataset: 'my-dataset', // Your axiom dataset
})
```

Add triggers for the worker, e.g a route trigger:
- Navigate to the worker and click on the `Triggers` tab.
- Scroll down to Routes and click `Add Route`.
- Enter a route, e.g `*.example.com` and choose the related zone,
then click `Save`.
Deploy your worker: `npm run deploy`

Your worker will now be available on a `.workers.dev` domain. To add additional routes, see the [Cloudflare documentation](https://developers.cloudflare.com/workers/configuration/routing/routes/).

When requests are made to the routes you setup, the worker will be triggered and you will see the logs delivered to your Axiom dataset.
Loading

0 comments on commit 6e458fc

Please sign in to comment.