diff --git a/.changeset/rude-birds-ring.md b/.changeset/rude-birds-ring.md new file mode 100644 index 000000000000..de998b0e55d3 --- /dev/null +++ b/.changeset/rude-birds-ring.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix build output adding `/index.html` at the end of endpoints route diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index ee398b99f56a..dd500e3488cf 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -161,7 +161,7 @@ async function generatePage( const timeEnd = performance.now(); const timeChange = getTimeStat(timeStart, timeEnd); const timeIncrease = `(+${timeChange})`; - const filePath = getOutputFilename(opts.astroConfig, path); + const filePath = getOutputFilename(opts.astroConfig, path, pageData.route.type); const lineIcon = i === paths.length - 1 ? '└─' : '├─'; info(opts.logging, null, ` ${cyan(lineIcon)} ${dim(filePath)} ${dim(timeIncrease)}`); } diff --git a/packages/astro/src/core/util.ts b/packages/astro/src/core/util.ts index bcfa6aab4f53..4087943808c9 100644 --- a/packages/astro/src/core/util.ts +++ b/packages/astro/src/core/util.ts @@ -5,7 +5,7 @@ import resolve from 'resolve'; import slash from 'slash'; import { fileURLToPath, pathToFileURL } from 'url'; import type { ErrorPayload, ViteDevServer } from 'vite'; -import type { AstroConfig } from '../@types/astro'; +import type { AstroConfig, RouteType } from '../@types/astro'; import { prependForwardSlash, removeTrailingForwardSlash } from './path.js'; // process.env.PACKAGE_VERSION is injected when we build and publish the astro package. @@ -33,7 +33,11 @@ const STATUS_CODE_REGEXP = /^\/?[0-9]{3}$/; * Handles both "/foo" and "foo" `name` formats. * Handles `/404` and `/` correctly. */ -export function getOutputFilename(astroConfig: AstroConfig, name: string) { +export function getOutputFilename(astroConfig: AstroConfig, name: string, type: RouteType) { + if (type === 'endpoint') { + return name; + } + if (name === '/' || name === '') { return path.posix.join(name, 'index.html'); }