Skip to content

Commit

Permalink
use built in csrf middleware (im stupid)
Browse files Browse the repository at this point in the history
  • Loading branch information
dromzeh committed Jan 4, 2024
1 parent 2048ac0 commit e7157a8
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 149 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Source code for the API powering [**wanderer.moe**](https://wanderer.moe) — us

We use Turso (libsql, fork of SQLite) as our database. You will need to install the [Turso CLI](https://docs.turso.tech/reference/turso-cli#installation) then run `turso dev` to start a local database. You can persist data by passing `--db-file <path>`.

The Turso CLI can be ran on Windows using WSL.
The Turso CLI can be run on Windows using WSL.

The API will connect to the local database if the environment is set to `DEV`, else - it will connect to your production database.

Expand All @@ -37,7 +37,7 @@ Required environment variables are viewable in `./src/worker-configuration.d.ts`

- There is a GitHub Action that automatically deploys to Cloudflare Workers on every push to `main` — you can find it in `.github/workflows/deploy.yml`.

- If you're using Github Actions, you will have to setup a secret with a Cloudflare API token. You can generate the API token [here][Cloudflare API Token] — use the `Edit Cloudflare Workers` template.
- If you're using GitHub Actions, you will have to set up a secret with a Cloudflare API token. You can generate the API token [here][Cloudflare API Token] — use the `Edit Cloudflare Workers` template.

### Database

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"better-sqlite3": "^9.2.2",
"drizzle-orm": "^0.29.2",
"drizzle-zod": "^0.5.1",
"hono": "^3.11.11",
"hono": "^3.12.0",
"lucia": "3.0.0-beta.14",
"oslo": "^0.26.2",
"prettier": "^3.1.1",
Expand Down
230 changes: 115 additions & 115 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { prettyJSON } from "hono/pretty-json"
import BaseRoutes from "@/v2/routes/handler"
import { CustomCSS, OpenAPIConfig } from "./openapi/config"
import { cors } from "hono/cors"
import { csrfValidation } from "./v2/middleware/csrf"
import { csrf } from "hono/csrf"
import { LogTime } from "./v2/middleware/time-taken"

const app = new OpenAPIHono<{ Bindings: Bindings; Variables: Variables }>()
Expand All @@ -26,8 +26,11 @@ app.get(
// openapi config
app.doc("/openapi", OpenAPIConfig)

// middleware
app.use("*", csrfValidation)
// middleware
// interface CSRFOptions {
// origin?: string | string[] | IsAllowedOriginHandler;
// }
app.use("*", csrf())
app.use("*", LogTime)

app.use(
Expand Down
27 changes: 0 additions & 27 deletions src/v2/middleware/csrf.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"paths": {
"@/*": ["src/*"]
},
"types": ["@cloudflare/workers-types"]
"types": ["@cloudflare/workers-types", "node"]
},
"include": ["src/**/*.ts"]
}

0 comments on commit e7157a8

Please sign in to comment.