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

Rewriting to the root doesn't work with trailingSlash: never & rewrite to non-existed page/404 issues #11235

Closed
1 task
vchirikov opened this issue Jun 11, 2024 · 4 comments · Fixed by #11272
Closed
1 task
Assignees
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@vchirikov
Copy link

Astro Info

astro 4.10.2

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

  1. rewriting to / doesn't work with trailingSlash: 'never' config setting
  2. rewriting to /404 doesn't work at all (with or without context (next('/404') and ctx.rewrite('/404')), might be the same behavior for 500 (?)
  3. astro's pipeline throws the same error type for a non-existed page or rendering error (so we don't know which error page should show - 404 or e.g. 500, it's bad for i18n )

bug

What's the expected result?

rewriting works fine with /404 and / with or without trailingSlash setting

Link to Minimal Reproducible Example

https://github.com/vchirikov/astro_issue_01

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jun 11, 2024
@matthewp matthewp added the - P4: important Violate documented behavior or significantly impacts performance (priority) label Jun 11, 2024
@github-actions github-actions bot removed the needs triage Issue needs to be triaged label Jun 11, 2024
@ematipico ematipico added - P3: minor bug An edge case that only affects very specific usage (priority) and removed - P4: important Violate documented behavior or significantly impacts performance (priority) labels Jun 11, 2024
@ematipico
Copy link
Member

Downgrading to a P3 because this is an experimental feature, and I doubt we have a lot of users using it

@vchirikov
Copy link
Author

@ematipico also I found that rewriting doesn't change the status code of response, e.g. I want to rewrite from /en/about to /pages/about.astro I do something like this:

const response = await next('/about');
console.log('return response from rewrite handler', response)
return response;

see nodejs in logs:

16:36:49 [watch] src/middleware.ts
return response from rewrite handler Response {
  status: 200,
  statusText: 'OK',
  headers: Headers {
    'content-type': 'text/html',
    'X-Astro-Route-Type': 'page',
    'X-Astro-Reroute': 'no'
  },
  body: ReadableStream { locked: false, state: 'readable', supportsBYOB: true },
  bodyUsed: false,
  ok: true,
  redirected: false,
  type: 'default',
  url: ''
}
16:36:49 [404] /en/about 187ms

note the response.status is 200, but astro returns 404 to the browser:

image

@vchirikov
Copy link
Author

@ematipico I've tested 4.11 and 404 on rewriting is still the issue

Again, the returned http status code is from /original-url not from /rewritten-url. Should I create a new issue or you will re-open this?

@ematipico
Copy link
Member

ematipico commented Jun 20, 2024

Please create a new one. I haven't seen the issue posted in the comment, sorry about that!

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.

3 participants