Open feedm3 opened 2 years ago
We also noticed that the Typescript Types for the headers
in GetServerDataReturn
are wrong. When you provide a new Map
, the headers are not used. You need to pass an object, which results in a type error:
Works (but has a type error):
export const getServerData = async (): GetServerDataReturn => {
return {
status: 301,
headers: {
'Location': '/'
}
}
}
Doesn't work (but typing is correct):
export const getServerData = async (): GetServerDataReturn => {
const headers = new Map();
headers.set('Location', '/');
return {
status: 301,
headers: headers
}
}
Hi!
When returning a redirect in the getServeData response, the redirect is not returned in the Gatsby dev mode, but it works when you do a gatsby build && gatsby serve
gatsby develop
and gatsby serve
differ in their setup so it's a matter of also implementing it into develop
. It was probably just forgotten.
We also noticed that the redirects don't work for Gatsby Cloud Preview environments (the builds for the pull requests)
Can you please open a bug report with cloud support? https://www.gatsbyjs.com/support/
We also noticed that the Typescript Types for the headers in GetServerDataReturn are wrong. When you provide a new Map, the headers are not used. You need to pass an object, which results in a type error
The types are incorrect here, it should be an object. Feel free to send in a PR fixing it! :)
Thanks @LekoArts for the response 🙂
For the issue with gatsby develop
I assume there is now a "ticket" somewhere and it will be implemented at some time?
Edit: Turns out there is already a suggestion in the forum to make redirects work in Gatsby Cloud Preview - give it an upvote if you read this! https://gatsby.canny.io/gatsby-cloud/p/functional-redirects-in-preview-builds
Update after merging the 404 SSR page and deploying it to production on Gatsby Cloud:
The 404 page is not triggered with "not found" pages. All we get is a standard 404 page from Gatsby Cloud. I contacted Gatsby Cloud support for this issue.
Code: https://github.com/satellytes/satellytes.com/blob/main/src/pages/%5B...%5D.tsx
@LekoArts Any updates or plans about the fallback SSR page with gatsby dev
?
I am also experiencing this issue with redirects and develop, need to build & serve to test my code which is slightly annoying. If you can point me to where the setup for that is on serve I would be glad to make a PR but have hard time finding it @LekoArts
Description
When returning a redirect in the
getServeData
response, the redirect is not returned in the Gatsby dev mode, but it works when you do agatsby build && gatsby serve
. We also noticed that the redirects don't work for Gatsby Cloud Preview environments (the builds for the pull requests). They work on the Gatsby Cloud production environment which is pushed to Gatsby Cloud Hosting though.The code we use to handle redirects looks like this:
Reproduction Link
/about-us/
Steps to Reproduce
The issue can be tested on the pull request here: https://github.com/satellytes/satellytes.com/pull/615
When you run
yarn start
, the redirect doesn't work. An HTML page is returned instead. Also the follow uppage-data.json
request returns the correct redirect, but this doesn't lead to a redirect in the browser:Screenshot
When build on localhost with
yarn build
and served withyarn serve
, the redirect works as expected:Screenshot
Expected Result
Correct redirects to the URL provided in the
Location
header.Actual Result
No redirect at all with
gatsby develop
or on Gatsby Cloud Preview.Environment
gatsby develop
Config Flags
None