Skip to content

Commit cbd0ed9

Browse files
committed
Initial Hono + D1 rewrite
Worker has been rewritten to use Hono router and Cloudflare D1 storage with Drizzle ORM
1 parent 871c68e commit cbd0ed9

27 files changed

+4660
-4007
lines changed

.github/workflows/e2e.yml

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ jobs:
55
cypress-run:
66
runs-on: ubuntu-latest
77
services:
8-
dynamodb:
9-
image: amazon/dynamodb-local:latest
10-
ports:
11-
- 8000:8000
128
minio:
139
image: bitnami/minio:latest
1410
env:
@@ -22,7 +18,7 @@ jobs:
2218
- name: Setup Node
2319
uses: actions/[email protected]
2420
with:
25-
node-version: 16
21+
node-version: 20
2622
- name: Get cache directory
2723
id: yarn-cache-dir-path
2824
run: echo "::set-output name=dir::$(yarn cache dir)"
@@ -34,13 +30,6 @@ jobs:
3430
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
3531
restore-keys: |
3632
${{ runner.os }}-yarn-
37-
- name: Create DynamoDB Table
38-
uses: giboow/action-aws-cli@v1
39-
with:
40-
args: dynamodb --endpoint-url http://dynamodb:8000 create-table --region eu-west-1 --table-name vh7 --key-schema AttributeName=id,KeyType=HASH --attribute-definitions AttributeName=id,AttributeType=S --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1
41-
env:
42-
AWS_ACCESS_KEY_ID: testid
43-
AWS_SECRET_ACCESS_KEY: testkey
4433
- name: Create S3 Bucket
4534
uses: giboow/action-aws-cli@v1
4635
with:
@@ -62,10 +51,6 @@ jobs:
6251
S3_DEFAULT_REGION: eu-west-1
6352
S3_ENDPOINT_URL: http://localhost:9000
6453
S3_BUCKET: vh7-uploads
65-
DYNAMODB_ACCESS_KEY_ID: testid
66-
DYNAMODB_SECRET_ACCESS_KEY: testkey
67-
DYNAMODB_TABLE: vh7
68-
DYNAMODB_ENDPOINT_URL: http://localhost:8000
6954
VH7_ENV: testing
7055
SENTRY_DSN: ${{ secrets.WORKER_SENTRY_DSN }}
7156
SENTRY_CLIENT_ID: ${{ secrets.WORKER_SENTRY_CLIENT_ID }}

.github/workflows/worker.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- name: Setup Node
1212
uses: actions/[email protected]
1313
with:
14-
node-version: 16
14+
node-version: 20
1515
- name: Get cache directory
1616
id: yarn-cache-dir-path
1717
run: echo "::set-output name=dir::$(yarn cache dir)"
@@ -27,16 +27,16 @@ jobs:
2727
working-directory: ./worker
2828
run: |
2929
yarn install --dev
30-
yarn global add @cloudflare/wrangler
30+
yarn global add wrangler
31+
- name: Migrate database
32+
working-directory: ./worker
33+
run: wrangler d1 migrations apply DB --local
3134
- name: Lint
3235
working-directory: ./worker
3336
run: yarn run lint
34-
# - name: Test
35-
# working-directory: ./worker
36-
# run: yarn run test
37-
- name: Build
37+
- name: Test
3838
working-directory: ./worker
39-
run: wrangler build
39+
run: yarn run test
4040
deploy:
4141
runs-on: ubuntu-latest
4242
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,4 @@ accessgrant.txt
208208
cleanup/backup-*
209209
app/cypress/downloads
210210
cleanup/prod.env
211+
.wrangler

cleanup/config.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

cleanup/index.js

Lines changed: 0 additions & 89 deletions
This file was deleted.

cleanup/package.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

docker-compose.dev.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
version: '3.8'
22
services:
3-
dynamodb:
4-
image: amazon/dynamodb-local:latest
5-
ports:
6-
- "8100:8000"
7-
init-dynamodb:
8-
image: amazon/aws-cli:latest
9-
command: "dynamodb --endpoint-url http://dynamodb:8000 create-table --region eu-west-1 --table-name vh7 --key-schema AttributeName=id,KeyType=HASH --attribute-definitions AttributeName=id,AttributeType=S --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1 > /dev/null"
10-
environment:
11-
- "AWS_ACCESS_KEY_ID=DUMMYIDEXAMPLE"
12-
- "AWS_SECRET_ACCESS_KEY=DUMMYEXAMPLEKEY"
13-
depends_on:
14-
dynamodb:
15-
condition: service_started
163
minio:
174
image: minio/minio:latest
185
command: "server /data -console-address ':9001'"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
CREATE TABLE short_link_paste (
2+
`short_link_id` text PRIMARY KEY NOT NULL,
3+
`code` text NOT NULL,
4+
`language` text,
5+
FOREIGN KEY (`short_link_id`) REFERENCES short_link(`id`)
6+
);
7+
8+
CREATE TABLE short_link_upload (
9+
`short_link_id` text PRIMARY KEY NOT NULL,
10+
`filename` text NOT NULL,
11+
`size` integer NOT NULL,
12+
`hash` text NOT NULL,
13+
FOREIGN KEY (`short_link_id`) REFERENCES short_link(`id`)
14+
);
15+
16+
CREATE TABLE short_link_url (
17+
`short_link_id` text PRIMARY KEY NOT NULL,
18+
`url` text NOT NULL,
19+
FOREIGN KEY (`short_link_id`) REFERENCES short_link(`id`)
20+
);
21+
22+
CREATE TABLE short_link (
23+
`id` text PRIMARY KEY NOT NULL,
24+
`created_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
25+
`updated_at` integer DEFAULT (cast((julianday('now') - 2440587.5)*86400000 as integer)) NOT NULL,
26+
`expires_at` integer,
27+
`type` text NOT NULL
28+
);

worker/package.json

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,36 @@
22
"name": "worker",
33
"version": "1.0.0",
44
"private": true,
5-
"main": "dist/worker.js",
65
"type": "module",
76
"devDependencies": {
8-
"@cloudflare/workers-types": "^3.3.0",
9-
"@types/itty-router-extras": "^0.4.0",
10-
"@types/service-worker-mock": "^2.0.1",
7+
"@cloudflare/workers-types": "^4.20230321.0",
118
"@typescript-eslint/eslint-plugin": "^5.8.0",
129
"@typescript-eslint/parser": "^5.8.0",
13-
"ava": "^4.0.1",
10+
"better-sqlite3": "^8.0.0",
11+
"drizzle-kit": "^0.20.13",
1412
"eslint": "^7.2.0",
1513
"eslint-config-airbnb-base": "^14.2.1",
1614
"eslint-config-airbnb-typescript": "^16.1.0",
1715
"eslint-plugin-import": "^2.22.1",
18-
"form-data": "^4.0.0",
19-
"miniflare": "",
20-
"ts-loader": "^9.2.6",
21-
"ts-node": "^10.4.0",
16+
"tsx": "^4.7.0",
2217
"typescript": "^4.5.4",
23-
"webpack": "^5.65.0",
24-
"webpack-cli": "^4.9.1"
18+
"vitest": "^1.2.1",
19+
"wrangler": "^3.24.0"
2520
},
2621
"dependencies": {
27-
"@aws-sdk/client-dynamodb": "^3.150.0",
28-
"@aws-sdk/lib-dynamodb": "^3.150.0",
2922
"aws4fetch": "^1.0.13",
30-
"itty-router": "^2.4.10",
31-
"itty-router-extras": "^0.4.2",
32-
"korma-kv": "^1.0.2",
23+
"drizzle-orm": "^0.29.3",
24+
"hono": "^3.12.7",
3325
"nanoid": "^3.1.30",
34-
"toucan-js": "^2.6.1",
35-
"zod": "^3.11.6"
26+
"zod": "^3.22.4"
3627
},
3728
"scripts": {
3829
"lint": "eslint ./src",
39-
"dev": "miniflare --debug --watch",
40-
"preview": "miniflare",
30+
"dev": "wranger dev",
4131
"build": "webpack",
4232
"publish": "wranger publish",
43-
"test": "yarn run build && ava --verbose test/*.spec.ts"
44-
},
45-
"ava": {
46-
"extensions": {
47-
"ts": "module"
48-
},
49-
"nodeArguments": [
50-
"--loader=ts-node/esm"
51-
]
33+
"test": "vitest --run",
34+
"migrate:generate": "drizzle-kit generate:sqlite --schema ./src/models.ts --out=./migrations",
35+
"migrate:up": "drizzle-kit up:sqlite"
5236
}
5337
}

worker/src/bindings.d.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)