Skip to content

Commit

Permalink
Use submit endpoint when authorised (#22)
Browse files Browse the repository at this point in the history
* Use submit endpoint when authorised

* Added prisma

* Deploy from branch

* Null check on member before accessing

* Improved handling for no token

* Fallback to non-secure endpoint on failure

* Remove unused variable

* Corrected log message

* Fixed syntax

* Read body once

* Carry over auth header

* log some of auth header

* Change header name

* Fix body on secure submit

* Add accept header

* add user-agent

* Added Host header

* Fix typo in header

---------

Co-authored-by: Jon Breen <[email protected]>
  • Loading branch information
cultpodcasts and cultpodcasts committed May 9, 2024
1 parent 82afd4c commit a65dee0
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 75 deletions.
7 changes: 7 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema

# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

DATABASE_URL=./.wrangler/state/d1/DB.sqlite3
8 changes: 5 additions & 3 deletions .github/workflows/buildAndDeploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ on:
push:
branches:
- main
- feature/authorization-header
- feature/new-router
- feature/direct-submit
jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
steps:
- uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4
- name: Build
run: npx prisma generate
- name: Publish
uses: cloudflare/wrangler-action@v3
with:
Expand Down
13 changes: 13 additions & 0 deletions migrations/0001_init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- Migration number: 0001 2024-05-09T09:28:45.679Z

-- CreateTable
CREATE TABLE "Submissions" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"url" TEXT NOT NULL,
"state" INTEGER NOT NULL DEFAULT 0,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"ip_address" TEXT,
"country" TEXT,
"user_agent" TEXT
);

107 changes: 102 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
"devDependencies": {
"@cloudflare/workers-types": "^4.20240423.0",
"typescript": "^5.0.4",
"wrangler": "^3.47.0"
"wrangler": "^3.53.1"
},
"dependencies": {
"@cfworker/jwt": "^4.0.6",
"hono": "^4.2.9"
"@prisma/adapter-d1": "^5.13.0",
"@prisma/client": "^5.13.0",
"hono": "^4.2.9",
"prisma": "^5.13.0"
}
}
22 changes: 22 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}

datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}

model Submissions {
id Int @id @default(autoincrement())
url String
state Int @default(0)
createdAt DateTime @default(now())
ip_address String?
country String?
user_agent String?
}
7 changes: 7 additions & 0 deletions src/Auth0JwtPayload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { JwtPayload } from '@cfworker/jwt';

export interface Auth0JwtPayload extends JwtPayload {
azp: string;
scope: string;
permissions: string[];
}
Loading

0 comments on commit a65dee0

Please sign in to comment.