netlify / netlify-plugin-gatsby

A build plugin to integrate Gatsby seamlessly with Netlify

Home Page:https://www.npmjs.com/package/@netlify/plugin-gatsby

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: Statuscode from getPageData is not applied

manuelJung opened this issue · comments

Summary

export async function getServerData() {
  return {
    status: 404,
    props: {},
  }
}

when my getServerData fn on a ssr route returns a 404 status (or any other statuscode) netlify will always send a 200 statuscode since this is hardcoded (which can be seen here). when data.serverDataStatus yields a 404 or 500 we should return the getErrorResponse fn instead

Steps to reproduce

  • create a gatsby project with an ssr route and add
export async function getServerData() {
  return {
    status: 404,
    props: {},
  }
}
  • deploy it to netlify (or serve with netlify locally)
  • call the ssr-route in the browser an see the statuscode send from netlify (it will be a 200)

! serving with gatsby (gatsby serve) wont work since here it works correctly)

A link to a reproduction repository

No response

Plugin version

3.8.0

More information about your build

  • I am building using the CLI
  • I am building using file-based configuration (netlify.toml)

What OS are you using?

Mac OS

Your netlify.toml file

`netlify.toml`
[build]
ignore = "exit 0"
functions = "./netlify/functions"
publish = "public/"

[build.environment]
NODE_OPTIONS = "--max_old_space_size=8192"

[[plugins]]
package = "@netlify/plugin-gatsby"

[[headers]]
for = "*"

[headers.values]
cache-control = """

                    max-age=0,
                    no-cache,
                    no-store,
                    must-revalidate"""

[[headers]]
for = "*.json"

[headers.values]
cache-control = """

                    private,
                    no-cache,
                    no-store"""

[[headers]]
for = "*.js"

[headers.values]
cache-control = """

                    public,
                    max-age=172800,
                    must-revalidate"""

Configuration

`gatsby-config.js` and options
# Paste content of your `gatsby-config.js` file, and/or command line options here. Check there is no private info in there.

Environment

Environment
System:
    OS: macOS 13.3
    CPU: (10) arm64 Apple M1 Max
    Memory: 2.88 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.11.0 - ~/.nvm/versions/node/v18.11.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.11.0/bin/yarn
    npm: 8.19.2 - ~/.nvm/versions/node/v18.11.0/bin/npm
  Browsers:
    Brave Browser: 114.1.52.130
    Chrome: 122.0.6261.94
    Safari: 16.4

Gatsby info

gatsby info
System:
    OS: macOS 13.3
    CPU: (10) arm64 Apple M1 Max
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.11.0 - ~/.nvm/versions/node/v18.11.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.11.0/bin/yarn
    npm: 8.19.2 - ~/.nvm/versions/node/v18.11.0/bin/npm
  Languages:
    Python: 2.7.18 - /Users/.../.pyenv/shims/python
  Browsers:
    Chrome: 122.0.6261.94
    Firefox: 120.0.1
    Safari: 16.4
  npmPackages:
    gatsby: ^5.10.0 => 5.11.0
    gatsby-plugin-eslint: ^4.0.4 => 4.0.4
    gatsby-plugin-google-tagmanager: ^5.10.0 => 5.11.0
    gatsby-plugin-graphql-codegen: ^3.1.1 => 3.1.1
    gatsby-plugin-manifest: ^5.10.0 => 5.11.0
    gatsby-plugin-netlify: ^5.1.0 => 5.1.0
    gatsby-plugin-react-helmet: ^6.10.0 => 6.11.0
    gatsby-plugin-react-svg: ^3.3.0 => 3.3.0
    gatsby-plugin-resolve-src: ^2.1.0 => 2.1.0
    gatsby-plugin-sitemap: ^6.10.0 => 6.11.0
    gatsby-plugin-typescript: ^5.10.0 => 5.11.0
  npmGlobalPackages:
    gatsby-cli: 5.10.0

Your _redirects file

`_redirects`
# Paste content of your `_redirects` file here

Builds logs (or link to your logs)

Build logs
# Paste logs here

Function logs

Function logs
# Paste logs here

I am afraid this issue is causing me some trouble as well. A fix would be highly appreciated.