[Bug]: Statuscode from getPageData is not applied

Problem: See Threadname and the already unanswered Github Issue: [Bug]: Statuscode from getPageData is not applied · Issue #749 · netlify/netlify-plugin-gatsby · GitHub

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: (netlify-plugin-gatsby/plugin/src/templates/handlers.ts at main · netlify/netlify-plugin-gatsby · GitHub)). 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)

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

Netlify.toml file

[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 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

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

Hi there,

Thanks for reaching out and providing all of this context, it’s super helpful! A minimal reproduction of the issue you’re hitting, though if possible, will also be helpful here, as I’m currently not able to replicate this with either @netlify/plugin-gatsby or the gatsby adapter, e.g: https://6614301c3243460c30c24ad8--ssr-status-test.netlify.app/ssr-page/

I’ve made the test repo public here: GitHub - littlemarcus/ssr-status-test. Looking forward to hearing from you!