Closed fnmendez closed 3 years ago
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 });
}
You'll need to open an issue on Cloudflare Workers instead. This package expects a compliant URL
object.
input:
https://flyyer.io/render?hey=123
config:
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.