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

Custom HTTP status pages (404, 403) have different build output #4418

Closed
1 task
vrilcode opened this issue Aug 22, 2022 · 4 comments · Fixed by #4497
Closed
1 task

Custom HTTP status pages (404, 403) have different build output #4418

vrilcode opened this issue Aug 22, 2022 · 4 comments · Fixed by #4497
Assignees
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@vrilcode
Copy link

vrilcode commented Aug 22, 2022

What version of astro are you using?

1.0.6

Are you using an SSR adapter? If so, which one?

none

What package manager are you using?

npm

What operating system are you using?

Mac

Describe the Bug

I have a 404.md and a 403.md in src/pages directory. If I execute astro build, I get a 404.html but a 403/index.html in dist directory. Although astro build-output says, that a 403.html was generated (which would be the intended behavior):

▶ src/pages/403.md
  └─ /403.html (+3ms)
▶ src/pages/404.md
  └─ /404.html (+2ms)
❯ ls -la dist
total 7
drwxr-xr-x  1  1  staff     5  Aug  22  12:27  ./            
drwxr-xr-x  1  1  staff    14  Aug  22  12:27  ../           
drwxrwxrwx  1  1  staff     1  Aug  22  12:27  403/          
-rw-rw-rw-  1  1  staff    35  Aug  22  12:27  404.html      
drwxrwxrwx  1  1  staff     1  Aug  22  12:27  assets/       
-rw-r--r--  1  1  staff  4286  Aug  22  12:27  favicon.ico   
-rw-rw-rw-  1  1  staff  2114  Aug  22  12:27  index.html 

On local development web server 403.md is actually available under /403.html.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-vyyavy-7kwypv

Participation

  • I am willing to submit a pull request for this issue.
@bholmesdev bholmesdev added the - P3: minor bug An edge case that only affects very specific usage (priority) label Aug 22, 2022
@bholmesdev
Copy link
Contributor

Thanks for reporting @cvh23! Double checking if this is special-cased for 404 pages, or if we should properly handle all status codes this way. I'll let @matthewp confirm!

@bholmesdev
Copy link
Contributor

Just touched base with @matthewp on this, and it sounds like this is intentional. Popular providers like Netlify support 404 handling via a 404.html, but not other status codes. So, we special-cased 404 routes specifically to avoid an index.html.

Today, you can change route/index.html -> route.html across the board by setting build.format: 'file' in our Astro config. Doing this route-by-route is a good idea though! Feel free to open a discussion here if you want that sort of feature.

Since this is expected behavior, I'll close this issue for now. Feel free to reply with thoughts though

@vrilcode
Copy link
Author

Thanks for your answer. But build process output is still stating, that 403.html was generated, which is not the case. Also local development server serves 403.html instead of generated 403/index.html. So there are still some issues, even if this is intentional.

Yes, would be good to have a common solution for HTTP status pages, not just 404.

@bholmesdev
Copy link
Contributor

bholmesdev commented Aug 26, 2022

Ah sorry, I forgot about that misleading console message. I'll reopen to work on a fix 👍

As for the dev server behavior, this is a side effect from Vite I'm afraid. Currently, you're allowed to access files on your file system from the dev server directly (either by their input or output file type), even when a given file won't be on your production build output. This is especially true for SSR, where .html outputs will not be generated for production but can be accessed from the server.

This is a more long-term fix worth raising with the Vite team. I'll make a note of it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants