Fix build output for endpoints route (#4273)

* Fix build output for endpoints route

* Add changeset
This commit is contained in:
Erika 2022-08-11 19:28:06 -04:00 committed by GitHub
parent d3d09a2c9f
commit 0022f46b57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix build output adding `/index.html` at the end of endpoints route

View file

@ -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)}`);
}

View file

@ -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');
}