MCPcopy Index your code
hub / github.com/freeCodeCamp/freeCodeCamp / getParamsFromUrl

Function getParamsFromUrl

api/src/utils/redirection.ts:99–122  ·  view source on GitHub ↗
(
  url: string | undefined | null,
  normalize: typeof normalizeParams
)

Source from the content-addressed store, hash-verified

97}
98
99function getParamsFromUrl(
100 url: string | undefined | null,
101 normalize: typeof normalizeParams
102) {
103 // since we do not always redirect the user back to the page they were on
104 // we need client locale and origin to construct the redirect url.
105 let returnUrl;
106 try {
107 returnUrl = new URL(url ? url : HOME_LOCATION);
108 } catch (_e) {
109 returnUrl = new URL(HOME_LOCATION);
110 }
111
112 const origin = returnUrl.origin;
113 // if this is not one of the client languages, validation will convert
114 // this to '' before it is used.
115 const pathPrefix = returnUrl.pathname.split('/')[1] ?? '';
116 return normalize({
117 // strip off any query parameters
118 returnTo: returnUrl.origin + returnUrl.pathname,
119 origin,
120 pathPrefix
121 });
122}
123
124/**
125 * Get the redirect parameters.

Callers 2

getRedirectParamsFunction · 0.85
getLoginRedirectParamsFunction · 0.85

Calls 1

normalizeFunction · 0.85

Tested by

no test coverage detected