Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node ssr dont showing 404 page #5535

Closed
1 task
polioan opened this issue Dec 5, 2022 · 11 comments
Closed
1 task

node ssr dont showing 404 page #5535

polioan opened this issue Dec 5, 2022 · 11 comments
Assignees
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)

Comments

@polioan
Copy link

polioan commented Dec 5, 2022

What version of astro are you using?

1.6.12

Are you using an SSR adapter? If so, which one?

node

What package manager are you using?

npm

What operating system are you using?

Windows (but linux have same behavior)

Describe the Bug

This behavior is similar on standalone and middleware mode. When using vite dev server - all ok, default or custom 404 page are showing. But when using build Instead of 404 page - plain text are showing.

run "npm run serve" for starting server in production (build) mode

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-cddzmd

Participation

  • I am willing to submit a pull request for this issue.
@bluwy bluwy added the - P4: important Violate documented behavior or significantly impacts performance (priority) label Dec 6, 2022
@bluwy bluwy self-assigned this Dec 7, 2022
@JerryWu1234
Copy link
Contributor

mark

@JerryWu1234
Copy link
Contributor

JerryWu1234 commented Dec 27, 2022

I know why can't appears 404 page that the user created. but I have a question about the default 404 page.

image
This page only appears in the dev.

Are you intentional?

@bluwy
Copy link
Member

bluwy commented Dec 27, 2022

@wulinsheng123 Yes I think that's intentional for dev only if the user doesn't provide a custom 404 page. For production, it should default to what the server would respond for 404.

Looking into the issue, looks like this is because we don't pass { matchNotFound: true } here. But we can't pass it because it might be a middleware, other middlewares might want to handle the request for something else instead of 404.

I think the fix here is that, if we're building for standalone mode, we set { matchNotFound: true }. For middleware mode, we can leave it as is, but a nice bonus feature is if the server build output export a second middleware that handles 404.html serving only.

@JerryWu1234
Copy link
Contributor

JerryWu1234 commented Dec 28, 2022

Thanks for your tips.
I will fix it hard this week。

@bluwy
Copy link
Member

bluwy commented Jan 13, 2023

Fixed in #5701

@bluwy bluwy closed this as completed Jan 13, 2023
@schroedan
Copy link

@bluwy Well, the problem was only half fixed. The 404 handler is missing in the middleware module exports. We can work around this in our case by building for standalone mode, setting ASTRO_NODE_AUTOSTART env to disabled and using the handler from the standalone module. But this is not a very clean way in my opinion.

@JerryWu1234
Copy link
Contributor

JerryWu1234 commented Feb 9, 2023

@bluwy Well, the problem was only half fixed. The 404 handler is missing in the middleware module exports. We can work around this in our case by building for standalone mode, setting ASTRO_NODE_AUTOSTART env to disabled and using the handler from the standalone module. But this is not a very clean way in my opinion.

could you give a minimal duplicated rep ?

@romannurik
Copy link

romannurik commented Aug 18, 2023

It's possible 298dbb8 may have broken this again? (or that commit fixes this in a future Astro version?)

@lilnasy
Copy link
Contributor

lilnasy commented Aug 19, 2023

@romannurik Some of the issues introduced by #7754 (released in astro v2.9.7) were fixed recently.

Please check with the latest version and if it's still there check the feat: 404 label to see if an issue for the bug is already open.

@romannurik
Copy link

romannurik commented Aug 20, 2023

@romannurik Some of the issues introduced by #7754 (released in astro v2.9.7) were fixed recently.

Please check with the latest version and if it's still there check the feat: 404 label to see if an issue for the bug is already open.

Thanks! Looks like I'm hitting this already reported issue, so I'll subscribe to updates there: #7881

EDIT: I actually think I'm hitting this one? Essentially my 404.astro, with prerender = false (in output=hybrid), using the node integration in middleware mode, renders the 404 in dev but not in prod

@romannurik
Copy link

FWIW, this horrid hack DOES work for me:

app.use(astroSsrHandler);
app.use((req, res, next) => {
  // only called if astroSsrHandler didn't handle this request originally
  req.url = '/404';
  astroSsrHandler(req, res, next);
});

So in my situation (see comment above), before this hack, visiting /404, or a page that returned new Response(null, { status: 404 }) correctly rendered the 404, but visiting some random non-existent URL seemed to be skipped over by the middleware

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)
Projects
None yet
Development

No branches or pull requests

6 participants