netlify/cli

`netlify serve` does not work with an Astro project using SSR and middleware

Closed this issue · 4 comments

Describe the bug

I'm trying to debug a production issue where Netlify is not serving the default Astro 404 page.
For example: https://test-default-404.netlify.app/sdfsdf doesn't show the default Astro 404.

Sentry also seems to report this error in production as NoMatchingRenderer. Public link to issue.

In development, running netlify dev and navigating to a legitimate 404 serves the Astro 404 page.

In order to try and see what was going on in production, I attempted to use netlify serve locally.

However, netlify serve, despite showing no errors in the console returns a 404 on ports 8888 (default port which is opened by the CLI in browser), 3999 (as shown for the static server in the console) and 4321 (default Astro port — which I need to use for netlify dev anyway due to using middleware via the Sentry integration).

Steps to reproduce

  1. Clone this project
  2. npm i
  3. Run netlify serve and observe that localhost:8888/3999/4321 returns a 404
  4. Run netlify dev and observe that localhost:4321/asd or localhost:8888/asd returns the default Astro 404

Configuration

[build]
  command = "npm run build"
  functions = "netlify/functions"
  publish = "dist"

Environment

System:
    OS: macOS 14.3.1
    CPU: (12) arm64 Apple M2 Pro
    Memory: 447.11 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.10.0/bin/yarn
    npm: 10.8.1 - ~/.nvm/versions/node/v20.10.0/bin/npm
    pnpm: 9.4.0 - ~/.nvm/versions/node/v20.10.0/bin/pnpm
  npmGlobalPackages:
    netlify-cli: 17.1.0

This is also me reporting that Netlify does not serve the correct Astro 404 in production, but was unable to find the correct place to file it, given there's no public repo for the Astro runtime.

I've replicated this using the Node adaptor so disregard this. The issue is with netlify serve only for this issue.

@whitep4nth3r Thanks for reporting this!

This was strictly speaking a limitation in the Netlify CLI: there were flows where it would automatically detect the framework and use the right settings (build command, publish directory, port, etc.) despite an absent netlify.toml with explicit configuration, but netlify serve was not one of those.

Incidentally, all these gaps were just closed this week (#6729)!

If you upgrade to the latest CLI version, you'll see netlify serve working in your demo repo now:

npm install -g netlify-cli@latest

(I was able to confirm this with your demo repo, before and after.)

I'll mark this as fixed, but please feel free to reopen if you're still having issues with this specific issue. Thanks!

... Just to be completely clear, since this is rather confusing (I'm confused too!), this issue is about how the index page / returns a 404 when using netlify serve, which is a separate, unrelated issue from withastro/adapters#291, which is about actual non-existing URLs returning a blank 404 page when using netlify serve, astro preview, or deploying to Netlify.

Thanks!