Repository: withastro/astro
File: packages/astro/src/core/routing/manifest/create.ts (TypeScript)

Code before:
	const injectedRoutes = createInjectedRoutes(params);
	for (const route of injectedRoutes) {
		routeMap.set(route.route, route);
	}

	const redirectRoutes = createRedirectRoutes(params, routeMap, logger);
	if (dev && config.base === '/') {
		// Add a redirect for `//` to `/`. We only do this in dev because different platforms
		// vary a lot in how or whether they handle this sort of redirect, so we leave it to the adapter
		redirectRoutes.push({
			type: 'redirect',
			isIndex: false,
			route: '//',
			pattern: /^\/+$/,
			segments: [],
			params: [],
			component: '/',
			generate: () => '//',
			pathname: '//',
			prerender: false,
			redirect: '/',
			redirectRoute: routeMap.get('/'),
			fallbackRoutes: [],
			distURL: [],
			origin: 'project',
		});
	}

	// we remove the file based routes that were deemed redirects
	const filteredFiledBasedRoutes = fileBasedRoutes.filter((fileBasedRoute) => {
		const isRedirect = redirectRoutes.findIndex((rd) => rd.route === fileBasedRoute.route);
		return isRedirect < 0;
	});

	const routes: RouteData[] = [
		...[...filteredFiledBasedRoutes, ...injectedRoutes, ...redirectRoutes].sort(routeComparator),
	];

	settings.buildOutput = getPrerenderDefault(config) ? 'static' : 'server';

	// Check the prerender option for each route
	const limit = pLimit(10);
	let promises = [];
	for (const route of routes) {
		promises.push(
			limit(async () => {
				if (route.type !== 'page' && route.type !== 'endpoint') return;
				const localFs = params.fsMod ?? nodeFs;
				const content = await localFs.promises.readFile(
					fileURLToPath(new URL(route.component, settings.config.root)),
					'utf-8',

Review comment (suggestion):
I would advise against creating full routes like this because many of those data might not be mandatory, and some of them need to be built using the proper functions. E.g. `getPattern` or `getRouteGenerator`.

Plus, we need to take into consideration things like `base`, `trailing slash` and more. Follow this pattern:

https://github.com/withastro/astro/blob/901c21f4f09bf61dfbb5ab04db2d7d90120383cb/packages/astro/src/core/routing/manifest/create.ts#L237-L261

It requires more code, but it's more reliable

Code after:
				if (route.type !== 'page' && route.type !== 'endpoint') return;
				const localFs = params.fsMod ?? nodeFs;
				const content = await localFs.promises.readFile(
					fileURLToPath(new URL(route.component, settings.config.root)),
					'utf-8',
				);

				await getRoutePrerenderOption(content, route, settings, logger);
			}),
		);
	}
	await Promise.all(promises);

	// Report route collisions
	for (const [index, higherRoute] of routes.entries()) {
		for (const lowerRoute of routes.slice(index + 1)) {
			detectRouteCollision(higherRoute, lowerRoute, config, logger);
		}
	}

	const i18n = settings.config.i18n;
	if (i18n) {
		const strategy = toRoutingStrategy(i18n.routing, i18n.domains);
		// First we check if the user doesn't have an index page.
		if (strategy === 'pathname-prefix-always') {
			let index = routes.find((route) => route.route === '/');
			if (!index) {
				let relativePath = path.relative(
					fileURLToPath(settings.config.root),
					fileURLToPath(new URL('pages', settings.config.srcDir)),
				);
				throw new AstroError({
					...MissingIndexForInternationalization,
					message: MissingIndexForInternationalization.message(i18n.defaultLocale),
					hint: MissingIndexForInternationalization.hint(relativePath),
				});
			}
		}

		// In this block of code we group routes based on their locale

		// A map like: locale => RouteData[]
		const routesByLocale = new Map<string, RouteData[]>();
		// This type is here only as a helper. We copy the routes and make them unique, so we don't "process" the same route twice.
		// The assumption is that a route in the file system belongs to only one locale.
		const setRoutes = new Set(routes.filter((route) => route.type === 'page'));

		// First loop
		// We loop over the locales minus the default locale and add only the routes that contain `/<locale>`.
		const filteredLocales = i18n.locales
			.filter((loc) => {