mjackson / unpkg

The CDN for everything on npm
https://unpkg.com
Other
3.01k stars 303 forks source link

Preserve URL Query Parameters #348

Open morganney opened 1 year ago

morganney commented 1 year ago

Is there any way to preserve query parameters other than ?module and ?meta when requesting a package? I've noticed that adding any other query parameter will result in a 302 redirect removing the query from the url.

My use case is to provide the ability to define an HTML custom element with a custom name upon loading. Currently my project uses a name query parameter from the import specifier to allow clients to customize the name used for the element.

Request: GET https://unpkg.com/tts-element@0.0.2-beta/dist/text-to-speech/defined.js?name=tts-ele Response: 302 Location: /tts-element@0.0.2-beta/dist/text-to-speech/defined.js

Are arbitrary query parameters not supported, or am I just missing something? The closest I've seen in regards to this issue is #93.

morganney commented 1 year ago

As a workaround I can provide documentation that suggests using another CDN, for example JSDelivr works without removing query parameters.

GET https://cdn.jsdelivr.net/npm/tts-element@0.0.2-beta/dist/text-to-speech/defined.js?name=my-tts returns a 200 allowing my element to work as expected when loaded with a query parameter in the specifier.

clshortfuse commented 1 year ago

I've noticed this as well. My web framework parses import.meta.url and applies the theme based on input

jsdeliver does work:

import { Button } from 'https://cdn.jsdelivr.net/npm/@shortfuse/materialdesignweb@0.7.1-7/dist/index.min.js?color=6750A4&custom=yellow,orange:orange,green:0f0,alias:aqua&lightness=auto';

But as described, unpkg will do a 302 redirect without the URL parameters.

It seems this is intentional:

https://github.com/mjackson/unpkg/blob/af8c8db00fdacd77961ab2a8c3edb45a27d3a6a3/modules/middleware/allowQuery.js#L6

Perhaps we add a special argument that force unpkg to pass arguments? Something like url?unpkgQuery&customParams=foo?