-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Rewrite leads to 404 followed by 302 when using Server Actions in Forms #12146
Comments
I am not really sure what you're trying to do, however this seems to be the expected behaviour. I need to understand why you have a
I am unsure we can achieve this, considering we use a middleware here. |
The reason that I'm using a rewrite is this: I am trying to have different "apps" within the same Astro project. Each app lives within a separate root folder, like The middleware inspects the requests and decides which app this particular user should be using. So a user navigates to So far, everything worked wonderfully, but after implementing an action, the issue arose. I think the issue comes down to Actions seem to do something under the hood that's not easy to understand for me (is there some more indepth documentation about how actions work internally?), and I can't seem to intercept to swap out internal and external paths. If the way actions are currently interacting with rewrites is the expected and correct way, I need to either avoid using actions altogether, or find another way to implement my multiple app folders within the project. |
Ok, I identified the issue and I have a PR ready, however, there's a bug of yours you should avoid. When rewriting, you should so only when At the moment, you're rewriting everything, even POST requests. A POST request is sent by your action with a |
Re-opening due to revert in #12206 |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
I have a middleware that rewrites the URL (
/post -> /with-post
and/action -> /with-action
).This works for regular GET and POST requests. For example, the
with-post.astro
page correctly handles the incoming form data:The server log of the GET and subsequent POST request look like this:
However, when using an Astro action, the rewrite does not work as expected, produces an internal 404 followed by an unwanted redirect and dropping the form data.
The server log of the GET and subsequent POST request look like this:
On the client, the POST request is responded with a 302 pointing to
/with-action
, which updates the URL in the browser.The action implementation is as expected:
What's the expected result?
I expect both implementations of the form to yield the same results. The action should not be influenced by the rewrite of the URL. A rewrite should not produce a 302 response.
Link to Minimal Reproducible Example
https://github.com/pothos-dev/astro-actions-rewrite
Participation
The text was updated successfully, but these errors were encountered: