From 0022f46b57946f4f71e7f9f6e265081ee4ae1565 Mon Sep 17 00:00:00 2001 From: Erika <3019731+Princesseuh@users.noreply.github.com> Date: Thu, 11 Aug 2022 19:28:06 -0400 Subject: [PATCH] Fix build output for endpoints route (#4273) * Fix build output for endpoints route * Add changeset --- .changeset/rude-birds-ring.md | 5 +++++ packages/astro/src/core/build/generate.ts | 2 +- packages/astro/src/core/util.ts | 8 ++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 .changeset/rude-birds-ring.md diff --git a/.changeset/rude-birds-ring.md b/.changeset/rude-birds-ring.md new file mode 100644 index 000000000..de998b0e5 --- /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 ee398b99f..dd500e348 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 bcfa6aab4..408794380 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'); }