Upgrade Wrangler to 3, Hono to 4
This commit is contained in:
parent
e07abe60f9
commit
a2f3b720b1
3 changed files with 483 additions and 800 deletions
1263
package-lock.json
generated
1263
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -6,19 +6,19 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"format": "prettier --write '**/*.{ts,js,css,json,md,html}'",
|
"format": "prettier --write '**/*.{ts,js,css,json,md,html}'",
|
||||||
"deploy": "wrangler publish",
|
"deploy": "wrangler deploy",
|
||||||
"dev": "wrangler dev",
|
"dev": "wrangler dev",
|
||||||
"addsecret": "wrangler secret put WORKERLINKS_SECRET",
|
"addsecret": "wrangler secret put WORKERLINKS_SECRET",
|
||||||
"createkv": "wrangler kv:namespace create KV && echo '^^^ Replace the binding on line 12 of wrangler.toml with this' ^^^",
|
"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"
|
"build": "wrangler publish --dry-run --outdir=./dist"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"hono": "^3.11.8",
|
"hono": "^4.2.1",
|
||||||
"simple-runtypes": "^7.1.3"
|
"simple-runtypes": "^7.1.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@cloudflare/workers-types": "^4.20231121.0",
|
"@cloudflare/workers-types": "^4.20231121.0",
|
||||||
"prettier": "^2.8.8",
|
"prettier": "^3.2.5",
|
||||||
"wrangler": "2.20.2"
|
"wrangler": "^3.44.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10
src/index.ts
10
src/index.ts
|
|
@ -39,7 +39,7 @@ const bulkValidator = st.dictionary(
|
||||||
)
|
)
|
||||||
|
|
||||||
const checkAuth = (c: Context) =>
|
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) =>
|
const unauthorized = (c: Context) =>
|
||||||
c.json({ code: '401 Unauthorized', message: 'Unauthorized' }, 401)
|
c.json({ code: '401 Unauthorized', message: 'Unauthorized' }, 401)
|
||||||
|
|
@ -230,7 +230,7 @@ app.post(ADMIN_PATH, async (c) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
async function createLink(c: Context) {
|
async function createLink(c: Context) {
|
||||||
const url = c.req.headers.get('URL')
|
const url = c.req.header('URL')
|
||||||
|
|
||||||
if (url == null || !validateUrl(url)) {
|
if (url == null || !validateUrl(url)) {
|
||||||
return c.json(
|
return c.json(
|
||||||
|
|
@ -282,15 +282,15 @@ app.all('*', (c) =>
|
||||||
async function sendToPlausible(c: Context) {
|
async function sendToPlausible(c: Context) {
|
||||||
const url = c.env.PLAUSIBLE_HOST + 'api/event'
|
const url = c.env.PLAUSIBLE_HOST + 'api/event'
|
||||||
const headers = new Headers()
|
const headers = new Headers()
|
||||||
headers.append('User-Agent', c.req.headers.get('User-Agent') || '')
|
headers.append('User-Agent', c.req.header('User-Agent') || '')
|
||||||
headers.append('X-Forwarded-For', c.req.headers.get('X-Forwarded-For') || '')
|
headers.append('X-Forwarded-For', c.req.header('X-Forwarded-For') || '')
|
||||||
headers.append('Content-Type', 'application/json')
|
headers.append('Content-Type', 'application/json')
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
name: 'pageview',
|
name: 'pageview',
|
||||||
url: c.req.url,
|
url: c.req.url,
|
||||||
domain: new URL(c.req.url).hostname,
|
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) })
|
await fetch(url, { method: 'POST', headers, body: JSON.stringify(data) })
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue