Skip to content

Commit

Permalink
feat: migrate the cloudflare worker into this repo (#530)
Browse files Browse the repository at this point in the history
* Refactor how the version and host properties are defined

These will be replaced via the webpack compile step later on

* Add first pass approach at building worker using webpack's node api

This is not working yet

* Getting it kinda working

* Getting webpack compilation working

* Move test/worker into worker/test before splitting out into separate repo

* Adding working compilation linked to readme

* Add generated scaffolding from yeoman generator

* Add dist to ignore files

* Fix lint issues

* Remove TODO from code

* Prettier

* Add case for invalid js being provided

* Add some better logging from within the worker

Make sure logs are turned off during testing

* Switch so that the recommended way of using this module is by setting the following headers:

- x-readme-id - id of the caller
- x-readme-label - label of the caller

* Remove the concept of compiling whatever code they send us

Just return the compiled code for a given host/apiKey

* Simplify compile step to just swap out apiKey in the dist file

This should make it much faster!

* There appears to be a bug with running `prepare` scripts in npm when installing from a git dependency, so i'm just gunna commit this for now and make sure this happens on prepublish

I think the correct place is a `prepare` script though

* Prefixing metrics api call with /v1

* Add circle ci config

* Add link to the docs in readme

* Adding `access: public` so it can be put onto npm

* 1.0.0

* Add latest dist

* Make sure to fetch and error about x-readme-* headers from the correct place

Right now this was broken, and we were expecting them to be set on the initial
request object (which would in effect mean from the originating HTTP request).

What we need to do is consume the original request, and make sure the *response*
from the backend API has these headers set. Then use the headers from here as
IDs to send to the metrics backend.

I've tested this using a local instance of hoot.at and ngrok with Cloudflare workers.

https://app.asana.com/0/681252538274980/923335774941624

* Attempting to fix CI with coverage

* 1.0.1

* Add latest dist

* Fix error message complaining about missing headers

We used to (incorrectly) look for these headers on the request object
then we switched to correctly looking on the API response, but I forgot
to change the error message.

* Default cf-connecting-ip header to 0.0.0.0

In cloudflare workers testing mode, this appears to be set to `null`
which causes validation errors from the metrics API

https://community.cloudflare.com/t/cf-connecting-ip-returns-null-in-latest-version-of-workers/13597/2

* 1.1.0

* Add latest dist

* feature complete: 1. Template for app store usage 2. Function handler for custom routing emulating cloudflare route matching

* Testing WIP

* Unit Testing complete

* Migrated regex to seperate file, changed path from lookbehind to lookahead, more test cases

* Replaced global key

* Update install.json

Co-Authored-By: domharrington <domharrington@users.noreply.github.com>

* Responded to PR comments, style changes

* migrate to prettier

* Remove compile function, unminify webpack

* Updated using cloudflare's env injection, test updates, endpoint updates

* ripped out unnecessary hook:

* Whitespace and casing

* fix: package.json points to the wrong git url (#6)

* test: setting up a workflow for running ci on github instead of circleci (#7)

* test: setting up a workflow for running ci on github instead of circleci

* test: removing circleci configs

* docs: swapping the ci badge on the readme

* build: 1.1.1 release

* Update ReadMe Link to Docs (#8)

* feature/allow-x-readme-email (#9)

* Prelim functionality for adding 'x-readme-email' to worker app:
dquote> We'd like to add more context to calls for our frontend, and we currently only support sending label/id. Adding email for this purpose

* Adding dist

* More test coverage

* docs: adding a security policy and pr template

* ci: setting up codeql

* feat: dependency overhauls (#11)

* ci: changing the ci workflow to run on LTS node versions

* chore: rebuilding the lockfile with npm7

* chore(deps-dev): loading in our coding standards

* test: moving tests over to using jest

* chore(deps-dev): removing module-alias as its now unused

* chore(deps-dev): bumping node-fetch

* feat: moving us to webpack@5

* ci: setting up dependabot

* ci: ignoring node-fetch updates as its now an ESM package

* docs: adding a code of conduct

* chore(deps): bump actions/setup-node from 2.4.0 to 2.4.1 (#13)

Bumps [actions/setup-node](https://github.com/actions/setup-node) from 2.4.0 to 2.4.1.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](actions/setup-node@v2.4.0...v2.4.1)

* chore(deps-dev): bump webpack from 5.53.0 to 5.55.1 (#14)

Bumps [webpack](https://github.com/webpack/webpack) from 5.53.0 to 5.55.1.
- [Release notes](https://github.com/webpack/webpack/releases)
- [Commits](webpack/webpack@v5.53.0...v5.55.1)

* chore(deps-dev): bump node-fetch from 2.6.2 to 2.6.5 (#15)

Bumps [node-fetch](https://github.com/node-fetch/node-fetch) from 2.6.2 to 2.6.5.
- [Release notes](https://github.com/node-fetch/node-fetch/releases)
- [Changelog](https://github.com/node-fetch/node-fetch/blob/v2.6.5/CHANGELOG.md)
- [Commits](node-fetch/node-fetch@v2.6.2...v2.6.5)

* chore(deps-dev): bump jest from 27.2.0 to 27.2.4 (#16)

Bumps [jest](https://github.com/facebook/jest) from 27.2.0 to 27.2.4.
- [Release notes](https://github.com/facebook/jest/releases)
- [Changelog](https://github.com/facebook/jest/blob/main/CHANGELOG.md)
- [Commits](jestjs/jest@v27.2.0...v27.2.4)

* chore(deps): bump actions/checkout from 2.3.4 to 2.3.5 (#17)

* chore(deps-dev): bump jest from 27.2.4 to 27.3.1 (#18)

* chore(deps-dev): bump @readme/eslint-config from 7.1.1 to 7.2.2 (#22)

* chore(deps-dev): bump nock from 13.1.3 to 13.1.4 (#23)

* ci: disabling dependabot

Disabling Dependabot for now until somebody has time to take this project under their wing.

* feat: directory cleanup and reorganization on the cloudflare worker

* chore: removing the editorconfig from the cloudflare package

Co-authored-by: Dom Harrington <dom@harrington-mail.com>
Co-authored-by: Dom Harrington <domharrington@protonmail.com>
Co-authored-by: Gabriel Ratcliff <gaberatcliff@gmail.com>
Co-authored-by: domharrington <domharrington@users.noreply.github.com>
Co-authored-by: Sean <dokko1230@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
7 people authored Aug 10, 2022
1 parent ea92da3 commit 78b4539
Show file tree
Hide file tree
Showing 29 changed files with 19,157 additions and 1,336 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/cloudflare-worker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: cloudflare-worker

on: [push]

jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: packages/cloudflare-worker

strategy:
matrix:
node-version:
- 14
- 16
- 18

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

# Node 14 still ships with npm@6 so for compatibility reasons we're upping
# this to match everything else.
- name: Install npm@8
if: matrix.node-version == '14'
run: npm install -g npm@8

- run: npm ci --ignore-scripts
- run: npm test
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
packages/cloudflare-worker/coverage/
packages/cloudflare-worker/dist/
packages/node/coverage/
packages/node/dist/
packages/php/vendor/
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Prettier's table formatting is cursed, hence this ignore block.
<!-- prettier-ignore-start -->
| | Language / Framework | Package | Latest Release |
| :--- |:--- | :--- | :--- |
| <img src="https://raw.githubusercontent.com/readmeio/metrics-sdks/main/docs/images/cloudflare-logo.svg" width="40" /> | Cloudflare Worker | [readmeio](https://github.com/readmeio/metrics-sdks/tree/main/packages/cloudflare-worker) | [![NPM](https://img.shields.io/npm/v/@readme/cloudflare-worker.svg)](https://npm.im/@readme/cloudflare-worker) ![Build status](https://img.shields.io/github/workflow/status/readmeio/metrics-sdks/cloudflare-worker.svg) |
| <img src="https://raw.githubusercontent.com/readmeio/metrics-sdks/main/docs/images/node-logo.svg" width="40" /> | NodeJS (Express) | [readmeio](https://github.com/readmeio/metrics-sdks/tree/main/packages/node) | [![NPM](https://img.shields.io/npm/v/readmeio.svg)](https://npm.im/readmeio) ![Build status](https://img.shields.io/github/workflow/status/readmeio/metrics-sdks/nodejs.svg) |
| <img src="https://raw.githubusercontent.com/readmeio/metrics-sdks/main/docs/images/php-logo.svg" width="40" /> | PHP (Laravel) | [readme/metrics](https://github.com/readmeio/metrics-sdks/tree/main/packages/php) | [![Packagist](https://img.shields.io/packagist/v/readme/metrics.svg)](https://packagist.org/packages/readme/metrics) ![Build status](https://img.shields.io/github/workflow/status/readmeio/metrics-sdks/php.svg) |
| <img src="https://raw.githubusercontent.com/readmeio/metrics-sdks/main/docs/images/python-logo.svg" width="40" /> | Python (Django, Flask, and WSGI) | [readme-metrics](https://github.com/readmeio/metrics-sdks/tree/main/packages/python) | [![PyPI](https://img.shields.io/pypi/v/readme-metrics.svg)](https://pypi.org/project/readme-metrics/) ![Build status](https://img.shields.io/github/workflow/status/readmeio/metrics-sdks/python.svg) |
Expand Down
Loading

0 comments on commit 78b4539

Please sign in to comment.