Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to a Cloudflare Worker #75

Merged
merged 47 commits into from
Jul 23, 2022
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
4c53236
Bump to Node.js 16.15.0
MattIPv4 May 20, 2022
44002ee
Base worker + testing for index routes
MattIPv4 May 21, 2022
c43eab2
Add JSDoc for new methods
MattIPv4 May 21, 2022
0f07495
Implement error handlers
MattIPv4 May 21, 2022
c8a8dbb
Implement stats endpoint
MattIPv4 May 21, 2022
5faf192
Implement whitelist endpoint
MattIPv4 May 21, 2022
10cbc91
Add status code checks to tests
MattIPv4 May 21, 2022
0f9f126
Implement tutorial endpoints
MattIPv4 May 21, 2022
e963b56
Implement library endpoints
MattIPv4 May 21, 2022
a7bb8ef
Implement libraries endpoint
MattIPv4 May 21, 2022
02c3df1
Fix eslint issues
MattIPv4 May 21, 2022
7c5d4d5
Update actions workflow for testing
MattIPv4 May 21, 2022
290ecdc
Add staging environment
MattIPv4 May 21, 2022
919aea8
Bump hono & remove query patch
MattIPv4 May 21, 2022
8f3218d
Add staging actions workflow
MattIPv4 May 22, 2022
66225c1
Run wrangler with npx
MattIPv4 May 22, 2022
8c37d94
Set fetch depth to 0
MattIPv4 May 22, 2022
1eda5f7
Scope Cf secrets to staging only
MattIPv4 May 22, 2022
c5fbb85
Add Sentry to main error handler
MattIPv4 May 23, 2022
73e06ae
Include Sentry calls for data issues
MattIPv4 May 23, 2022
2f4f865
Inject Sentry vars during staging workflow
MattIPv4 May 23, 2022
5cbcddf
Don't fail on Sentry release if force pushed
MattIPv4 May 24, 2022
823d887
Fix Sentry stack frames for source mapping
MattIPv4 May 24, 2022
bc67595
Merge branch 'master' into MattIPv4/worker
MattIPv4 May 24, 2022
28d55f6
Add production workflow
MattIPv4 May 24, 2022
60964aa
Update readme to reflect worker rewrite
MattIPv4 May 25, 2022
3859353
Bump hono, remove tutorial short-circuit for library version
MattIPv4 May 27, 2022
5b56be5
Bump babel/eslint deps
MattIPv4 May 27, 2022
e515442
Add support for passing through to origin
MattIPv4 May 27, 2022
a908b08
Bump hono + miniflare + wrangler
MattIPv4 May 28, 2022
50eaccd
Update comment on queryArray for clarity
MattIPv4 Jun 8, 2022
010785c
README copy tweaks
MattIPv4 Jun 8, 2022
e4874e3
Optional chaining goodness
MattIPv4 Jun 8, 2022
324e13b
Add comment explaining fetch-depth: 0 usage
MattIPv4 Jun 8, 2022
f9d88cc
Remove redundant fetch method in all tests
MattIPv4 Jun 8, 2022
93ef2e2
Remove fragile search query for invalid fields test
MattIPv4 Jun 8, 2022
68d0428
Allow nullable latest for invalid search fields test
MattIPv4 Jun 8, 2022
31922ed
Use origin 100% for production
MattIPv4 Jun 10, 2022
fa3af24
Clarity on comments for chai response modification
MattIPv4 Jun 11, 2022
784db11
Reduce production to 99% origin usage
MattIPv4 Jun 13, 2022
985d41c
Reduce production to 90% origin usage
MattIPv4 Jun 13, 2022
03b43e9
Only return assets for the latest version of a library
MattIPv4 Jun 15, 2022
4f9dc49
Set ignore_empty on Sentry release step
MattIPv4 Jun 18, 2022
3615055
Reduce production to 75% origin usage
MattIPv4 Jul 18, 2022
50c9cfd
Reduce production to 50% origin usage
MattIPv4 Jul 19, 2022
125b353
Reduce production to 25% origin usage
MattIPv4 Jul 20, 2022
7ba4772
Reduce production to 0% origin usage
MattIPv4 Jul 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ insert_final_newline = true
[Makefile]
indent_style = tab
indent_size = tab

[*.yml]
indent_size = 2
223 changes: 223 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
module.exports = {
root: true,
env: {
browser: true,
es2022: true,
},
parser: '@babel/eslint-parser',
parserOptions: {
sourceType: 'module',
requireConfigFile: false,
},
plugins: [
'jsdoc',
],
extends: [
'eslint:recommended',
'plugin:import/recommended',
'plugin:jsdoc/recommended',
],
settings: {
jsdoc: {
mode: 'typescript',
preferredTypes: {
object: 'Object',
'Array<>': '[]',
'Array.<>': '[]',
'Object.<>': '<>',
},
tagNamePreference: {
returns: 'return',
augments: 'extends',
},
},
},
rules: {
'space-before-function-paren': [
'error',
{
anonymous: 'always',
named: 'never',
asyncArrow: 'always',
},
],
'arrow-parens': [
'error',
'as-needed',
],
'arrow-body-style': [
'error',
'as-needed',
],
'arrow-spacing': 'error',
'object-curly-spacing': [
'error',
'always',
],
'array-bracket-spacing': [
'error',
'always',
],
'no-console': 'off',
'no-var': 'error',
'prefer-const': 'error',
indent: [
'error',
4,
],
semi: [
'error',
'always',
],
quotes: [
'error',
'single',
'avoid-escape',
],
'quote-props': [
'error',
'as-needed',
],
'object-curly-newline': [
'error',
{
multiline: true,
consistent: true,
},
],
'comma-dangle': [
'error',
'always-multiline',
],
'comma-spacing': [
'error',
{
before: false,
after: true,
},
],
'comma-style': [
'error',
'last',
],
'eol-last': 'error',
'key-spacing': [
'error',
{
beforeColon: false,
afterColon: true,
},
],
'keyword-spacing': [
'error',
{
before: true,
after: true,
},
],
'block-spacing': 'error',
'space-in-parens': [
'error',
'never',
],
'space-before-blocks': 'error',
'no-trailing-spaces': 'error',
'semi-spacing': [
'error',
{
before: false,
after: true,
},
],
'space-infix-ops': 'error',
'linebreak-style': [
'error',
'unix',
],
'max-len': [
'error',
{
code: 120,
ignoreComments: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
},
],
'no-param-reassign': [
'error',
{
props: false,
},
],
'no-unused-vars': [
'error',
],
'no-unused-expressions': [
'error',
{
allowTaggedTemplates: true,
},
],
'import/order': [
'error',
{
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
'newlines-between': 'always',
},
],
'import/no-unresolved': [
'error',
{
ignore: [
'^hono/',
],
},
],
'jsdoc/require-returns-description': 'off',
'jsdoc/tag-lines': 'off',
'jsdoc/no-undefined-types': [
'error',
{
definedTypes: [
'RequestInit',
'RequestInfo',
],
},
],
'jsdoc/require-jsdoc': [
'error',
{
require: {
ArrowFunctionExpression: true,
ClassDeclaration: true,
ClassExpression: true,
FunctionDeclaration: true,
FunctionExpression: true,
MethodDefinition: true,
},
},
],
},
overrides: [
{
files: [ '**/spec/**/*.js', '**/*.spec.js' ],
rules: {
'no-unused-expressions': 'off',
'jsdoc/require-jsdoc': 'off',
},
},
{
files: [ '*.cjs' ],
parserOptions: {
sourceType: 'script',
},
env: {
node: true,
es2022: true,
},
},
],
};
92 changes: 0 additions & 92 deletions .eslintrc.js

This file was deleted.

60 changes: 60 additions & 0 deletions .github/workflows/production-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Deploy to Production

on:
push:
branches:
- production

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout Commit
uses: actions/checkout@v3
with:
fetch-depth: 0 # Get the full history for the Sentry release commit log

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc
cache: npm

- name: Install Dependencies
run: npm ci

- name: Run Tests
run: npm test

- name: Prepare Wrangler Config
run: |
SENTRY_DSN=$(printf '%s\n' "${{ secrets.SENTRY_DSN }}" | sed -e 's/[\/&]/\\&/g')
MattIPv4 marked this conversation as resolved.
Show resolved Hide resolved
sed -i "s/SENTRY_DSN = \"\"/SENTRY_DSN = \"$SENTRY_DSN\"/g" wrangler.toml
MattIPv4 marked this conversation as resolved.
Show resolved Hide resolved

SENTRY_RELEASE=$(printf '%s\n' "${{ github.sha }}" | sed -e 's/[\/&]/\\&/g')
sed -i "s/SENTRY_RELEASE = \"\"/SENTRY_RELEASE = \"$SENTRY_RELEASE\"/g" wrangler.toml

- name: Deploy to Production
run: npx wrangler publish --env production --outdir dist-worker --minify
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN_PRODUCTION }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID_PRODUCTION }}

- name: Prepare Sentry Release
run: |
mv dist-worker/index.js dist-worker/worker.js
mv dist-worker/index.js.map dist-worker/worker.js.map

- name: Create Sentry Release
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
url_prefix: /
ignore_missing: true
version: ${{ github.sha }}
environment: production
sourcemaps: dist-worker
Loading