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

Function handleRedirects

api/src/plugins/auth-dev.ts:14–23  ·  view source on GitHub ↗
(req: FastifyRequest, reply: FastifyReply)

Source from the content-addressed store, hash-verified

12 str.endsWith('/') ? str.slice(0, -1) : str;
13
14async function handleRedirects(req: FastifyRequest, reply: FastifyReply) {
15 const params = getRedirectParams(req);
16 const { origin, pathPrefix } = params;
17 const returnTo = trimTrailingSlash(params.returnTo);
18 const landingUrl = getPrefixedLandingPath(origin, pathPrefix);
19
20 return await reply.redirect(
21 haveSamePath(landingUrl, returnTo) ? `${returnTo}/learn` : returnTo
22 );
23}
24
25/**
26 * Fastify plugin for dev authentication.

Callers 1

devAuthFunction · 0.85

Calls 4

getRedirectParamsFunction · 0.85
trimTrailingSlashFunction · 0.85
getPrefixedLandingPathFunction · 0.85
haveSamePathFunction · 0.85

Tested by

no test coverage detected