Skip to content

Commit

Permalink
Fix build output for endpoints route (#4273)
Browse files Browse the repository at this point in the history
* Fix build output for endpoints route

* Add changeset
  • Loading branch information
Princesseuh authored Aug 11, 2022
1 parent d3d09a2 commit 0022f46
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-birds-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix build output adding `/index.html` at the end of endpoints route
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
Expand Down
8 changes: 6 additions & 2 deletions packages/astro/src/core/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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');
}
Expand Down

0 comments on commit 0022f46

Please sign in to comment.