render.ts — astro Source File
Architecture documentation for render.ts, a typescript file in the astro codebase. 3 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 257bae1e_85a4_d9fb_5253_5efdfeba739a["render.ts"] baa53824_73a3_1e03_2043_4d0c058ecca5["../types/public/index.js"] 257bae1e_85a4_d9fb_5253_5efdfeba739a --> baa53824_73a3_1e03_2043_4d0c058ecca5 7e14fb1f_4abe_1438_9c6e_bb382e90b0fe["../core/render-context.js"] 257bae1e_85a4_d9fb_5253_5efdfeba739a --> 7e14fb1f_4abe_1438_9c6e_bb382e90b0fe 162316ad_87a9_ee43_993e_48696ea31a8d["../core/routing/manifest/generator.js"] 257bae1e_85a4_d9fb_5253_5efdfeba739a --> 162316ad_87a9_ee43_993e_48696ea31a8d style 257bae1e_85a4_d9fb_5253_5efdfeba739a fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import type { RedirectConfig } from '../../types/public/index.js';
import type { RenderContext } from '../render-context.js';
import { getRouteGenerator } from '../routing/manifest/generator.js';
export function redirectIsExternal(redirect: RedirectConfig): boolean {
if (typeof redirect === 'string') {
return redirect.startsWith('http://') || redirect.startsWith('https://');
} else {
return (
redirect.destination.startsWith('http://') || redirect.destination.startsWith('https://')
);
}
}
export async function renderRedirect(renderContext: RenderContext) {
const {
request: { method },
routeData,
} = renderContext;
const { redirect, redirectRoute } = routeData;
const status =
redirectRoute && typeof redirect === 'object' ? redirect.status : method === 'GET' ? 301 : 308;
const headers = { location: encodeURI(redirectRouteGenerate(renderContext)) };
if (redirect && redirectIsExternal(redirect)) {
if (typeof redirect === 'string') {
return Response.redirect(redirect, status);
} else {
return Response.redirect(redirect.destination, status);
}
}
return new Response(null, { status, headers });
}
function redirectRouteGenerate(renderContext: RenderContext): string {
const {
params,
routeData: { redirect, redirectRoute },
pipeline,
} = renderContext;
if (typeof redirectRoute !== 'undefined') {
const generate = getRouteGenerator(redirectRoute.segments, pipeline.manifest.trailingSlash);
return generate(params) || redirectRoute?.pathname || '/';
} else if (typeof redirect === 'string') {
if (redirectIsExternal(redirect)) {
return redirect;
} else {
let target = redirect;
for (const param of Object.keys(params)) {
const paramValue = params[param]!;
target = target.replace(`[${param}]`, paramValue).replace(`[...${param}]`, paramValue);
}
return target;
}
} else if (typeof redirect === 'undefined') {
return '/';
}
return redirect.destination;
}
Domain
Subdomains
Dependencies
- ../core/render-context.js
- ../core/routing/manifest/generator.js
- ../types/public/index.js
Source
Frequently Asked Questions
What does render.ts do?
render.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in render.ts?
render.ts defines 3 function(s): redirectIsExternal, redirectRouteGenerate, renderRedirect.
What does render.ts depend on?
render.ts imports 3 module(s): ../core/render-context.js, ../core/routing/manifest/generator.js, ../types/public/index.js.
Where is render.ts in the architecture?
render.ts is located at packages/astro/src/core/redirects/render.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/core/redirects).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free