createRoutesFile() — astro Function Reference
Architecture documentation for the createRoutesFile() function in generate-routes-json.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 8640426d_7494_3130_6574_2a01f8ff809d["createRoutesFile()"] da981689_3d65_7d59_3c95_800d340ef108["generate-routes-json.ts"] 8640426d_7494_3130_6574_2a01f8ff809d -->|defined in| da981689_3d65_7d59_3c95_800d340ef108 af0cdc9e_8242_4e0c_ac86_586602e54c28["segmentsToCfSyntax()"] 8640426d_7494_3130_6574_2a01f8ff809d -->|calls| af0cdc9e_8242_4e0c_ac86_586602e54c28 09d00deb_054d_d337_2af6_8adce8a3f9f0["getParts()"] 8640426d_7494_3130_6574_2a01f8ff809d -->|calls| 09d00deb_054d_d337_2af6_8adce8a3f9f0 50db76a0_b0ab_7605_0653_203d0278f34d["insert()"] 8640426d_7494_3130_6574_2a01f8ff809d -->|calls| 50db76a0_b0ab_7605_0653_203d0278f34d 298714b3_acee_7cfa_6509_a32cf6723cc8["reduceAllPaths()"] 8640426d_7494_3130_6574_2a01f8ff809d -->|calls| 298714b3_acee_7cfa_6509_a32cf6723cc8 fb74c78c_04f8_7b51_cb60_ee71ba657144["getAllPaths()"] 8640426d_7494_3130_6574_2a01f8ff809d -->|calls| fb74c78c_04f8_7b51_cb60_ee71ba657144 372324f0_ccf6_ade0_f068_23df832924f7["writeRoutesFileToOutDir()"] 8640426d_7494_3130_6574_2a01f8ff809d -->|calls| 372324f0_ccf6_ade0_f068_23df832924f7 style 8640426d_7494_3130_6574_2a01f8ff809d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/integrations/cloudflare/src/utils/generate-routes-json.ts lines 166–346
export async function createRoutesFile(
_config: AstroConfig,
logger: AstroIntegrationLogger,
routes: IntegrationResolvedRoute[],
pages: {
pathname: string;
}[],
redirects: IntegrationResolvedRoute['segments'][],
includeExtends:
| {
pattern: string;
}[]
| undefined,
excludeExtends:
| {
pattern: string;
}[]
| undefined,
) {
const includePaths: string[][] = [];
const excludePaths: string[][] = [];
/**
* All files in the `_config.build.assets` path, e.g. `_astro`
* are considered static assets and should not be handled by the function
* therefore we exclude a wildcard for that, e.g. `/_astro/*`
*/
const assetsPath = segmentsToCfSyntax(
[
[{ content: _config.build.assets, dynamic: false, spread: false }],
[{ content: '', dynamic: true, spread: false }],
],
_config,
);
excludePaths.push(assetsPath);
for (const redirect of redirects) {
excludePaths.push(segmentsToCfSyntax(redirect, _config));
}
if (existsSync(fileURLToPath(_config.publicDir))) {
const staticFiles = await glob(`**/*`, {
cwd: fileURLToPath(_config.publicDir),
dot: true,
});
for (const staticFile of staticFiles) {
if (['_headers', '_redirects', '_routes.json'].includes(staticFile)) continue;
const staticPath = staticFile;
const segments = removeLeadingForwardSlash(staticPath)
.split(path.sep)
.filter(Boolean)
.map((s: string) => {
return getParts(s);
});
excludePaths.push(segmentsToCfSyntax(segments, _config));
}
}
let hasPrerendered404 = false;
for (const route of routes) {
const convertedPath = segmentsToCfSyntax(route.segments, _config);
if (route.pathname === '/404' && route.isPrerendered === true) hasPrerendered404 = true;
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
switch (route.type) {
case 'page':
if (route.isPrerendered === false) includePaths.push(convertedPath);
break;
case 'endpoint':
if (route.isPrerendered === false) includePaths.push(convertedPath);
else excludePaths.push(convertedPath);
break;
case 'redirect':
excludePaths.push(convertedPath);
break;
Domain
Subdomains
Source
Frequently Asked Questions
What does createRoutesFile() do?
createRoutesFile() is a function in the astro codebase, defined in packages/integrations/cloudflare/src/utils/generate-routes-json.ts.
Where is createRoutesFile() defined?
createRoutesFile() is defined in packages/integrations/cloudflare/src/utils/generate-routes-json.ts at line 166.
What does createRoutesFile() call?
createRoutesFile() calls 6 function(s): getAllPaths, getParts, insert, reduceAllPaths, segmentsToCfSyntax, writeRoutesFileToOutDir.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free