Skip to content

Commit

Permalink
Upgrade deps, use URL.canParse for URL validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Erisa committed Nov 27, 2023
1 parent 8630490 commit faa950a
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 137 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"simple-runtypes": "^7.1.3"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20230228.0",
"@cloudflare/workers-types": "^4.20231121.0",
"prettier": "^2.8.8",
"wrangler": "^2.20.1"
}
Expand Down
14 changes: 1 addition & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ app.get('/', async (c) => {
// retrieve key
app.get('*', handleGetHead)

// same but for HEAD
app.head('*', handleGetHead)

// handle both GET and HEAD
async function handleGetHead(c: Context) {
// actual logic goes here
Expand Down Expand Up @@ -297,16 +294,7 @@ async function sendToPlausible(c: Context) {
}

function validateUrl(url: string) {
// quick and dirty validation
if (url == '') {
return false
}
try {
new URL(url)
} catch (TypeError) {
return false
}
return true
return URL.canParse(url)
}

export default app
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"esModuleInterop": true,
"strict": true,
"lib": ["esnext"],
"types": ["@cloudflare/workers-types"],
"types": ["@cloudflare/workers-types/2023-03-01"],
"jsx": "react-jsx",
// "jsxFragmentFactory": "Fragment",
"jsxImportSource": "hono/jsx"
Expand Down
2 changes: 1 addition & 1 deletion wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ kv_namespaces = [
]

compatibility_flags = []
compatibility_date = "2023-03-05"
compatibility_date = "2023-03-01"

# Remove or comment out the route line if using workers_dev (and set below to true)
workers_dev = false
Expand Down
Loading

0 comments on commit faa950a

Please sign in to comment.