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

Code before:
									pattern: getPattern(segments, config.base, config.trailingSlash),
									type: 'fallback',
									fallbackRoutes: [],
								};
								const routeData = routes[index];
								routeData.fallbackRoutes.push(fallbackRoute);
							}
						}
					}
				}
			}
		}
	}

	if (dev) {
		ensure404Route({ routes });
		injectImageEndpoint(settings, { routes }, 'dev');
		injectServerIslandRoute(settings.config, { routes });
	} else if (settings.buildOutput === 'server') {
		injectImageEndpoint(settings, { routes }, 'build');
		// We can't only inject this route when server islands are used because:
		// - To know if we use serve islands, we need to build
		// - The build runs before we can inject the server island route
		injectServerIslandRoute(settings.config, { routes });
		// In SSR, a 404 route is injected in the App directly for some special handling,
		// it must not appear in the manifest
	}
	await runHookRoutesResolved({ routes, settings, logger });

	return {
		routes,
	};
}

export function resolveInjectedRoute(entrypoint: string, root: URL, cwd?: string) {
	let resolved;
	try {
		resolved = require.resolve(entrypoint, { paths: [cwd || fileURLToPath(root)] });
	} catch {
		resolved = fileURLToPath(new URL(entrypoint, root));
	}

	return {
		resolved: resolved,
		component: slash(path.relative(cwd || fileURLToPath(root), resolved)),
	};
}

function joinSegments(segments: RoutePart[][]): string {
	const arr = segments.map((segment) => {
		return segment.map((rp) => (rp.dynamic ? `[${rp.content}]` : rp.content)).join('');

Review comment (suggestion):
Can't we write the code like this? Less branching and less repetition.

```js
if (dev || severOutput) {
	if (dev) { ensure404() }
	injectInternaloutes()
}
```

It would be nice to have a generic function called `injectInternalRoutes`, so future routes to add can be added to this new function

Code after:
									pattern: getPattern(segments, config.base, config.trailingSlash),
									type: 'fallback',
									fallbackRoutes: [],
								};
								const routeData = routes[index];
								routeData.fallbackRoutes.push(fallbackRoute);
							}
						}
					}
				}
			}
		}
	}

	if (dev) {
		// In SSR, a 404 route is injected in the App directly for some special handling,
		// it must not appear in the manifest
		ensure404Route({ routes });
	}
	if (dev || settings.buildOutput === 'server') {
		injectImageEndpoint(settings, { routes }, dev ? 'dev' : 'build');
		// Ideally we would only inject the server islands route if server islands are used in the project.
		// Unforunately, there is a "circular dependency": to know if server islands are used, we need to run
		// the build but the build relies on the routes manifest.
		// This situation also means we cannot update the buildOutput based on wether or not server islands
		// are used in the project. If server islands are detected after the build but the buildOutput is
		// static, we fail the build.
		injectServerIslandRoute(settings.config, { routes });
	}
	await runHookRoutesResolved({ routes, settings, logger });

	return {
		routes,
	};
}

export function resolveInjectedRoute(entrypoint: string, root: URL, cwd?: string) {
	let resolved;
	try {
		resolved = require.resolve(entrypoint, { paths: [cwd || fileURLToPath(root)] });
	} catch {
		resolved = fileURLToPath(new URL(entrypoint, root));
	}

	return {
		resolved: resolved,
		component: slash(path.relative(cwd || fileURLToPath(root), resolved)),
	};
}

function joinSegments(segments: RoutePart[][]): string {