Not working properly on Cloudflare Workers
Closed this issue · 2 comments
fnmendez commented
input: https://flyyer.io/render?hey=123
config:
{
defaultProtocol: "https:",
normalizeProtocol: true,
stripHash: true,
stripWWW: false,
stripAuthentication: true,
removeQueryParameters: [/^utm_\w+/i],
removeTrailingSlash: false,
sortQueryParameters: true,
}
output : https://@flyyer.io/render?hey=123#
expected: https://flyyer.io/render?hey=123
The URL object on Cloudflare Workers is different. It seems that only the href
methods behaves differently.
fnmendez commented
BetterURL along with normalize-url
do all the work nicely.
import { BetterURL } from "@flyyer/better-url";
import normalizeUrl from "normalize-url"; // normalizeUrl is failing because URL class is different on Cloudflare workers
export function NORMALIZE_URL(link: string): string {
const betterURL = new BetterURL(
normalizeUrl(link, {
defaultProtocol: "https:",
normalizeProtocol: true,
stripHash: true,
stripWWW: false,
stripAuthentication: true,
removeQueryParameters: [/^utm_\w+/i],
removeTrailingSlash: false,
// removeSingleSlash: true,
sortQueryParameters: true,
}),
);
return betterURL.format({ protocol: true, hostname: true, pathname: true, search: true });
}
sindresorhus commented
You'll need to open an issue on Cloudflare Workers instead. This package expects a compliant URL
object.