Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only print file output only for 404 and 500 routes #4497

Merged
merged 2 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/modern-schools-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Production build logging - Only log `[code].html` instead of `[code]/index.html` for 404 and 500 routes
9 changes: 4 additions & 5 deletions packages/astro/src/core/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function padMultilineString(source: string, n = 2) {
return lines.map((l) => ` `.repeat(n) + l).join(`\n`);
}

const STATUS_CODE_REGEXP = /^\/?[0-9]{3}$/;
const REGEXP_404_OR_500_ROUTE = /(404)|(500)\/?$/;

/**
* Get the correct output filename for a route, based on your config.
Expand All @@ -37,14 +37,13 @@ export function getOutputFilename(astroConfig: AstroConfig, name: string, type:
if (type === 'endpoint') {
return name;
}

if (name === '/' || name === '') {
return path.posix.join(name, 'index.html');
}
if (astroConfig.build.format === 'directory' && !STATUS_CODE_REGEXP.test(name)) {
return path.posix.join(name, 'index.html');
if (astroConfig.build.format === 'file' || REGEXP_404_OR_500_ROUTE.test(name)) {
return `${removeTrailingForwardSlash(name || 'index')}.html`;
}
return `${removeTrailingForwardSlash(name || 'index')}.html`;
return path.posix.join(name, 'index.html');
}

/** is a specifier an npm package? */
Expand Down