-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Incorrect static file endpoint paths in dev (and prod build output) with trailingSlash: true (OP responded) #9674
Comments
@lilnasy try writing code or just creating a link that points to that json file (per your example). you will need to add a slash on the end for it to not 404, which is useless and not reflective of production. Related, the build output is incorrect as well: This is actually why I thought that the endpoint paths were messed up in prod as well, my bad for trusting the build output and not checking the actual dist folder. Sorry for the confusion there. The build output does not reflect the reality that you have observed, which is the expected result: Either way there's definitely a bug when the dev server and the build process doesn't reflect production when it comes to static file endpoint paths, it arguably compromises its purpose as a dev server! As I noted the |
…`action` property points to an external URL.(withastro#9674)
…`action` property points to an external URL.(withastro#9674)
…`action` property points to an external URL.(withastro#9674)
…`action` property points to an external URL.(withastro#9674)
I've just hit this while making Starlight work with SSR by prerendering all its routes. With |
If you want endpoints that do not have trailingSlash then |
I am going to close this one. It's not the first time users were "surprised" that We will discuss if it's worth to allowlist "known" extensions, for provide an option. Still, that's not a bug. |
@matthewp + @ematipico imho the feature only makes sense when it applies to pages...
If you had a strong case for the first point, I imagine you'd then agree that the second point is a bug because the discrepancy will inevitably lead to production issues with Astro sites (plus add a layer of complexity with creating conditional URL's depending on dev vs. production). Why does the trailingSlash feature exist?Per Astro docs https://docs.astro.build/en/reference/configuration-reference/#trailingslash (emphasis mine):
Common real-world cloud deployment exampleSuppose architecture of an AWS S3-hosted Astro project with CloudFront up-front. Many providers use this architecture under-the-hood as well as other AWS services (Amplify) and this example is transferable to other cloud providers. One must use either an Edge Lambda or CloudFront Function to implement what Astro would call the trailing slash behaviour. This is where one decides if URL's should end in a trailing slash or not, and how the site should behave when serving a request for a URL that either ends or does not end in a trailing slash. When it comes to pages and a request comes in e.g. When it comes to files, i.e. requests with pathnames that end with a file extension, then we need to allow the request through. For example: This is why, imho, Since this is so common the AWS docs provide complete code example for both Edge Lambdas and CloudFront Functions. e.g. add index.html to requests that don't include a file name: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/example-function-add-index.html In production I use something more elaborate to check if a request is for a page vs. file vs. the naive example because dots are valid in filenames (I check for file types etc. and also handle MIME types correctly etc.) however the overall idea is exactly the same. The general approach is also the same on both Astro SSG and SSR projects I have deployed. ConclusionIf It also means:
At the very least, even if you disagree, maybe you can propose other features for Astro config that should be added? |
Do you want something like |
@lilnasy that would be awesome and would be really appreciated! I hope that the dev server vs. build output discrepancy also doesn't get lost in this shuffle. |
You are right, Astro should make sure that dev behaves the same as production server. However, that becomes impossible when the production server is not an Astro SSR app. There are too many static web servers with their own conventions. It's not realistic to have complete parity with them. The only thing we can offer is making our code do what the options say. And "pages" seems like it could be among them. |
I appreciate the challenge you face here having worked on both Astro SSR and SSG projects! I specifically chose the example of an OG image on an SSG blog to highlight the dev vs. prod discrepancy issue since this is such a popular usage for Astro, and a case where I agree with your standpoint that code should do what the options say and I really like your |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
For an SSG site with
trailingSlash: always
in the config, the static file endpoints feature (see docs) should output files not directories in both dev server and production build.Edit As clarified below in the comments:
/pathname/to/file.json
erroneously produces/pathname/to/file.json/
resulting in a disagreement between dev and production that will lead to bugs in projectsastro build
process generates the expected output in the dist folder (e.g./pathname/to/file.json
) however its console output reports an incorrect directory path similar to how the dev server behaves:/pathname/to/file.json/
(screenshot is below in the comments)The
trailingSlash: always
functionality is crucial to preventing issues with links, etc. in projects because it enforces the requirements of production hosting environment during development and QA.What's the expected result?
Refer to StackBlitz: https://stackblitz.com/edit/github-gxpxsn?file=astro.config.mjs
The static file generation feature is expected to work as-documented.
I should be able to use the feature to generate OG images, RSS feeds, robots.txt, and more on an Astro SSG project, regardless of what my
trailingSlash
andbuild.format
settings are. Routing should work as expected.In the StackBlitz I note that on my local project Astro is working as expected for static file generation for files in the base of
src/pages
but not in subfolders or with dynamic routing, but in the StackBlitz version there are also issues here too.Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-gxpxsn?file=astro.config.mjs
Participation
The text was updated successfully, but these errors were encountered: