Case-insensitive routing in Workers

Hi all, appreciate if someone can help me on the following two questions.

  1. What would you suggest to create a case-insensitive routing in Cloudflare Workers? The existing template is case-sensitive. Only thing I could think of is to check path:
    const url = new URL(request.url)
    const path = url.pathname
    and get path.toLowerCase() value. Do you think this makes sense?

  2. Another thing I was searching but could not find a reply is how can we distinguish whether a npm package can be used in a worker project? I know the packages that uses node api can not be imported, but what about non-node-api ones? In the tutorial, I see some of the packages can be used (like qr tutorial)

Thanks

Yes, you can use npm packages.

In order to use the npm packages, you need to update your worker type to webpack.

// wrangler.toml
name = "YOUR_WORKER_NAME"
type = "webpack"
// ...