Next.js Discord

Discord Forum

Redirect from another website returns invalid url on first load

Answered
maslomeister posted this in #help-forum
Open in Discord
Hello there, i have next js 14.0.4 website which works fine, but when another website links to my website like so

<form action="https://mywebsite.com/" target="top" method="POST"><input type="submit" class="button_big" style="min-width:150px;margin:5px 0px 0px 0px;" value="get price"></form>


On first load my website shows this error
TypeError [ERR_INVALID_URL]: Invalid URL
    at new NodeError (node:internal/errors:405:5)
    //stuff//
{
  input: 'null',
  code: 'ERR_INVALID_URL',
  page: '/'
}


if i refresh that page everything works as expected, i have no idea what's going on
Answered by maslomeister
Adding middleware for specific route and rewriting POST request using 301 fixed this
View full answer

3 Replies

Full error code in attached txt file
So this happens because it sends POST request to the page which expects GET request, is there a way to somehow redirect it from POST to GET or serve page.tsx to this POST request? I have no control over the website that creates this broken POST redirect and they are not going to fix it to work properly
Adding middleware for specific route and rewriting POST request using 301 fixed this
Answer