Skip to content

Commit a66a3fb

Browse files
authored
Migrate to a Cloudflare Worker (#75)
* Bump to Node.js 16.15.0 * Base worker + testing for index routes * Add JSDoc for new methods * Implement error handlers * Implement stats endpoint * Implement whitelist endpoint * Add status code checks to tests * Implement tutorial endpoints * Implement library endpoints * Implement libraries endpoint * Fix eslint issues * Update actions workflow for testing * Add staging environment * Bump hono & remove query patch * Add staging actions workflow * Run wrangler with npx * Set fetch depth to 0 * Scope Cf secrets to staging only * Add Sentry to main error handler * Include Sentry calls for data issues * Inject Sentry vars during staging workflow * Don't fail on Sentry release if force pushed * Fix Sentry stack frames for source mapping * Add production workflow * Update readme to reflect worker rewrite * Bump hono, remove tutorial short-circuit for library version * Bump babel/eslint deps * Add support for passing through to origin * Bump hono + miniflare + wrangler * Update comment on queryArray for clarity * README copy tweaks * Optional chaining goodness * Add comment explaining fetch-depth: 0 usage * Remove redundant fetch method in all tests * Remove fragile search query for invalid fields test * Allow nullable latest for invalid search fields test * Use origin 100% for production * Clarity on comments for chai response modification * Reduce production to 99% origin usage * Reduce production to 90% origin usage * Only return assets for the latest version of a library * Set ignore_empty on Sentry release step * Reduce production to 75% origin usage * Reduce production to 50% origin usage * Reduce production to 25% origin usage * Reduce production to 0% origin usage
1 parent c5197ff commit a66a3fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+9952
-3255
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ insert_final_newline = true
1212
[Makefile]
1313
indent_style = tab
1414
indent_size = tab
15+
16+
[*.yml]
17+
indent_size = 2

.eslintrc.cjs

+223
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
browser: true,
5+
es2022: true,
6+
},
7+
parser: '@babel/eslint-parser',
8+
parserOptions: {
9+
sourceType: 'module',
10+
requireConfigFile: false,
11+
},
12+
plugins: [
13+
'jsdoc',
14+
],
15+
extends: [
16+
'eslint:recommended',
17+
'plugin:import/recommended',
18+
'plugin:jsdoc/recommended',
19+
],
20+
settings: {
21+
jsdoc: {
22+
mode: 'typescript',
23+
preferredTypes: {
24+
object: 'Object',
25+
'Array<>': '[]',
26+
'Array.<>': '[]',
27+
'Object.<>': '<>',
28+
},
29+
tagNamePreference: {
30+
returns: 'return',
31+
augments: 'extends',
32+
},
33+
},
34+
},
35+
rules: {
36+
'space-before-function-paren': [
37+
'error',
38+
{
39+
anonymous: 'always',
40+
named: 'never',
41+
asyncArrow: 'always',
42+
},
43+
],
44+
'arrow-parens': [
45+
'error',
46+
'as-needed',
47+
],
48+
'arrow-body-style': [
49+
'error',
50+
'as-needed',
51+
],
52+
'arrow-spacing': 'error',
53+
'object-curly-spacing': [
54+
'error',
55+
'always',
56+
],
57+
'array-bracket-spacing': [
58+
'error',
59+
'always',
60+
],
61+
'no-console': 'off',
62+
'no-var': 'error',
63+
'prefer-const': 'error',
64+
indent: [
65+
'error',
66+
4,
67+
],
68+
semi: [
69+
'error',
70+
'always',
71+
],
72+
quotes: [
73+
'error',
74+
'single',
75+
'avoid-escape',
76+
],
77+
'quote-props': [
78+
'error',
79+
'as-needed',
80+
],
81+
'object-curly-newline': [
82+
'error',
83+
{
84+
multiline: true,
85+
consistent: true,
86+
},
87+
],
88+
'comma-dangle': [
89+
'error',
90+
'always-multiline',
91+
],
92+
'comma-spacing': [
93+
'error',
94+
{
95+
before: false,
96+
after: true,
97+
},
98+
],
99+
'comma-style': [
100+
'error',
101+
'last',
102+
],
103+
'eol-last': 'error',
104+
'key-spacing': [
105+
'error',
106+
{
107+
beforeColon: false,
108+
afterColon: true,
109+
},
110+
],
111+
'keyword-spacing': [
112+
'error',
113+
{
114+
before: true,
115+
after: true,
116+
},
117+
],
118+
'block-spacing': 'error',
119+
'space-in-parens': [
120+
'error',
121+
'never',
122+
],
123+
'space-before-blocks': 'error',
124+
'no-trailing-spaces': 'error',
125+
'semi-spacing': [
126+
'error',
127+
{
128+
before: false,
129+
after: true,
130+
},
131+
],
132+
'space-infix-ops': 'error',
133+
'linebreak-style': [
134+
'error',
135+
'unix',
136+
],
137+
'max-len': [
138+
'error',
139+
{
140+
code: 120,
141+
ignoreComments: true,
142+
ignoreStrings: true,
143+
ignoreTemplateLiterals: true,
144+
},
145+
],
146+
'no-param-reassign': [
147+
'error',
148+
{
149+
props: false,
150+
},
151+
],
152+
'no-unused-vars': [
153+
'error',
154+
],
155+
'no-unused-expressions': [
156+
'error',
157+
{
158+
allowTaggedTemplates: true,
159+
},
160+
],
161+
'import/order': [
162+
'error',
163+
{
164+
alphabetize: {
165+
order: 'asc',
166+
caseInsensitive: true,
167+
},
168+
'newlines-between': 'always',
169+
},
170+
],
171+
'import/no-unresolved': [
172+
'error',
173+
{
174+
ignore: [
175+
'^hono/',
176+
],
177+
},
178+
],
179+
'jsdoc/require-returns-description': 'off',
180+
'jsdoc/tag-lines': 'off',
181+
'jsdoc/no-undefined-types': [
182+
'error',
183+
{
184+
definedTypes: [
185+
'RequestInit',
186+
'RequestInfo',
187+
],
188+
},
189+
],
190+
'jsdoc/require-jsdoc': [
191+
'error',
192+
{
193+
require: {
194+
ArrowFunctionExpression: true,
195+
ClassDeclaration: true,
196+
ClassExpression: true,
197+
FunctionDeclaration: true,
198+
FunctionExpression: true,
199+
MethodDefinition: true,
200+
},
201+
},
202+
],
203+
},
204+
overrides: [
205+
{
206+
files: [ '**/spec/**/*.js', '**/*.spec.js' ],
207+
rules: {
208+
'no-unused-expressions': 'off',
209+
'jsdoc/require-jsdoc': 'off',
210+
},
211+
},
212+
{
213+
files: [ '*.cjs' ],
214+
parserOptions: {
215+
sourceType: 'script',
216+
},
217+
env: {
218+
node: true,
219+
es2022: true,
220+
},
221+
},
222+
],
223+
};

.eslintrc.js

-92
This file was deleted.
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Deploy to Production
2+
3+
on:
4+
push:
5+
branches:
6+
- production
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout Commit
14+
uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 0 # Get the full history for the Sentry release commit log
17+
18+
- name: Install Node.js
19+
uses: actions/setup-node@v3
20+
with:
21+
node-version-file: .nvmrc
22+
cache: npm
23+
24+
- name: Install Dependencies
25+
run: npm ci
26+
27+
- name: Run Tests
28+
run: npm test
29+
30+
- name: Prepare Wrangler Config
31+
run: |
32+
SENTRY_DSN=$(printf '%s\n' "${{ secrets.SENTRY_DSN }}" | sed -e 's/[\/&]/\\&/g')
33+
sed -i "s/SENTRY_DSN = \"\"/SENTRY_DSN = \"$SENTRY_DSN\"/g" wrangler.toml
34+
35+
SENTRY_RELEASE=$(printf '%s\n' "${{ github.sha }}" | sed -e 's/[\/&]/\\&/g')
36+
sed -i "s/SENTRY_RELEASE = \"\"/SENTRY_RELEASE = \"$SENTRY_RELEASE\"/g" wrangler.toml
37+
38+
- name: Deploy to Production
39+
run: npx wrangler publish --env production --outdir dist-worker --minify
40+
env:
41+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN_PRODUCTION }}
42+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID_PRODUCTION }}
43+
44+
- name: Prepare Sentry Release
45+
run: |
46+
mv dist-worker/index.js dist-worker/worker.js
47+
mv dist-worker/index.js.map dist-worker/worker.js.map
48+
49+
- name: Create Sentry Release
50+
uses: getsentry/action-release@v1
51+
env:
52+
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
53+
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
54+
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
55+
with:
56+
url_prefix: /
57+
ignore_missing: true
58+
ignore_empty: true
59+
version: ${{ github.sha }}
60+
environment: production
61+
sourcemaps: dist-worker

0 commit comments

Comments
 (0)