Upgrade Wrangler to 3, Hono to 4

This commit is contained in:
Erisa A 2024-04-03 19:51:41 +01:00
parent e07abe60f9
commit a2f3b720b1
No known key found for this signature in database
3 changed files with 483 additions and 800 deletions

1265
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -6,19 +6,19 @@
"license": "MIT",
"scripts": {
"format": "prettier --write '**/*.{ts,js,css,json,md,html}'",
"deploy": "wrangler publish",
"deploy": "wrangler deploy",
"dev": "wrangler dev",
"addsecret": "wrangler secret put WORKERLINKS_SECRET",
"createkv": "wrangler kv:namespace create KV && echo '^^^ Replace the binding on line 12 of wrangler.toml with this' ^^^",
"build": "wrangler publish --dry-run --outdir=./dist"
},
"dependencies": {
"hono": "^3.11.8",
"hono": "^4.2.1",
"simple-runtypes": "^7.1.3"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20231121.0",
"prettier": "^2.8.8",
"wrangler": "2.20.2"
"prettier": "^3.2.5",
"wrangler": "^3.44.0"
}
}

View file

@ -39,7 +39,7 @@ const bulkValidator = st.dictionary(
)
const checkAuth = (c: Context) =>
c.req.headers.get('Authorization') === c.env.WORKERLINKS_SECRET
c.req.header('Authorization') === c.env.WORKERLINKS_SECRET
const unauthorized = (c: Context) =>
c.json({ code: '401 Unauthorized', message: 'Unauthorized' }, 401)
@ -230,7 +230,7 @@ app.post(ADMIN_PATH, async (c) => {
})
async function createLink(c: Context) {
const url = c.req.headers.get('URL')
const url = c.req.header('URL')
if (url == null || !validateUrl(url)) {
return c.json(
@ -282,15 +282,15 @@ app.all('*', (c) =>
async function sendToPlausible(c: Context) {
const url = c.env.PLAUSIBLE_HOST + 'api/event'
const headers = new Headers()
headers.append('User-Agent', c.req.headers.get('User-Agent') || '')
headers.append('X-Forwarded-For', c.req.headers.get('X-Forwarded-For') || '')
headers.append('User-Agent', c.req.header('User-Agent') || '')
headers.append('X-Forwarded-For', c.req.header('X-Forwarded-For') || '')
headers.append('Content-Type', 'application/json')
const data = {
name: 'pageview',
url: c.req.url,
domain: new URL(c.req.url).hostname,
referrer: c.req.referrer,
referrer: c.req.header('referer'),
}
await fetch(url, { method: 'POST', headers, body: JSON.stringify(data) })
}