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

404 page doesn't render in production mode #8054

Closed
1 task
xriter opened this issue Aug 13, 2023 · 19 comments · Fixed by #8141
Closed
1 task

404 page doesn't render in production mode #8054

xriter opened this issue Aug 13, 2023 · 19 comments · Fixed by #8141
Labels
- P2: has workaround Bug, but has workaround (priority) feat: error pages Related to 404 and 500 handling (scope) pkg: node Related to Node adapter (scope)

Comments

@xriter
Copy link

xriter commented Aug 13, 2023

What version of astro are you using?

2.10.7

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

Node

What package manager are you using?

npm

What operating system are you using?

Mac

What browser are you using?

Safari

Describe the Bug

In SSR mode, when going to a page that doesn't exist, the 404 page should be rendered (the default or custom one). It does this correctly in dev mode, but in production mode it only renders a blank page.

Using @astrojs/node 5.3.3 with node v18.16.1

Also see the repro.
Run npm run build && npm run preview and go to /doesntexist.

What's the expected result?

The 404 page should be rendered correctly in SSR production mode.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-trfvka?file=src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Aug 13, 2023
@natemoo-re
Copy link
Member

Guessing that this will be closed by #8070 which fixes a few edge cases introduced in #7754

@natemoo-re natemoo-re added the - P4: important Violate documented behavior or significantly impacts performance (priority) label Aug 14, 2023
@github-actions github-actions bot removed the needs triage Issue needs to be triaged label Aug 14, 2023
@lilnasy
Copy link
Contributor

lilnasy commented Aug 15, 2023

@xriter Could not reproduce the issue.

Works the same in dev and build on stackblitz.

@xriter
Copy link
Author

xriter commented Aug 15, 2023

@lilnasy I made a little 🎞️ screen recording showing how to reproduce in Stackblitz.
Check out the video: https://github.com/withastro/astro/assets/70454441/6c1b6748-99b0-4b80-9c41-39e055ed95d1

(Besides that I also experience this problem in real world projects of course).

@lilnasy
Copy link
Contributor

lilnasy commented Aug 15, 2023

Is there a difference when you run node dist/server/entry.mjs instead of npm run preview?

@xriter
Copy link
Author

xriter commented Aug 15, 2023

@lilnasy I just tried. When running node dist/server/entry.mjs the 404 page DOES render indeed. 🤔
So what's the difference? I guess it also still should be working correctly when running npm run preview? (At least it did so before...)

Although, I run a website in production in a Docker container, (that is using node dist/server/entry.mjs), and there it does not work... Wondering if it has something to do with the domain or dns (localhost vs 127.0.0.1)...

@lilnasy lilnasy added - P2: has workaround Bug, but has workaround (priority) and removed - P4: important Violate documented behavior or significantly impacts performance (priority) labels Aug 15, 2023
@lilnasy lilnasy changed the title 404 page doesn't render in production mode 404 page doesn't render in preview mode Aug 15, 2023
@xriter
Copy link
Author

xriter commented Aug 15, 2023

@lilnasy Not fully convinced about the workaround tag. See my updated previous comment. 🙈

@lilnasy
Copy link
Contributor

lilnasy commented Aug 15, 2023

Although, I run a website in production in a Docker container, (that is using node dist/server/entry.mjs), and there it does not work...

If the 404 page was prerendered, it may have been an issue introduced recently.

@xriter
Copy link
Author

xriter commented Aug 15, 2023

If the 404 page was prerendered, it may have been an issue introduced recently.

It uses the custom 404.astro, and no prerender variable was set. I believe it then always does SSR right?

@lilnasy
Copy link
Contributor

lilnasy commented Aug 15, 2023

It should, unless the output config is "hybrid".

@xriter
Copy link
Author

xriter commented Aug 15, 2023

It should, unless the output config is "hybrid".

The config is set as

output: "server",
adapter: node({
    mode: "standalone",
}),

From the docs (https://docs.astro.build/en/guides/server-side-rendering/#enabling-ssr-in-your-project) I understand that in that case you don't set const prerender = true.

@lilnasy lilnasy added the pkg: node Related to Node adapter (scope) label Aug 15, 2023
@xriter xriter changed the title 404 page doesn't render in preview mode 404 page doesn't render in production mode Aug 15, 2023
@lilnasy
Copy link
Contributor

lilnasy commented Aug 15, 2023

Yeah, prerendering-related issues are probably not the culprit then. However, it might need another reproduction to investigate that issue.

@xriter
Copy link
Author

xriter commented Aug 15, 2023

@lilnasy I do think the Important tag should be reapplied, since the assumed workaround doesn't actually work in the production environment (Docker).

@lilnasy
Copy link
Contributor

lilnasy commented Aug 15, 2023

the assumed workaround doesn't actually work in the production environment (Docker).

Could you share the dockerfile so I can try to confirm?

@xriter
Copy link
Author

xriter commented Aug 15, 2023

Dockerfile

FROM node:18-slim
WORKDIR /app
COPY ./package.json ./
RUN npm install --production=false --verbose
COPY . .
RUN npm run build --verbose

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 astro

USER astro
ENV HOST=0.0.0.0
ENV PORT 8001
EXPOSE 8001
CMD node ./dist/server/entry.mjs

docker-compose.yml

version: "3.7"

services:
    node:
        build:
            context: .
            args:
                NODE_ENV: production
        working_dir: /app
        env_file:
            - .env
        environment:
            - NODE_ENV=production
        ports:
            - "8001:8001"
        restart: unless-stopped

@lilnasy
Copy link
Contributor

lilnasy commented Aug 15, 2023

Couldn't reproduce it with docker either.

Temporary link to running project with docker run --rm -it -p 8001:8001 7b80

@xriter
Copy link
Author

xriter commented Aug 15, 2023

Very interesting. I don't understand. I use those configurations. On a VPS, using reverse proxies; which keeps me looking in the area of something with dns resolving?

It worked fine before. After 'some' update (don't know which version number) it just stopped. I get it to repro with npm run preview on stackblitz. You agree there's 'something' not how it's supposed to be, right?

@lilnasy
Copy link
Contributor

lilnasy commented Aug 15, 2023

Yes, I could reproduce the issue when running npm run preview.

@xriter
Copy link
Author

xriter commented Aug 15, 2023

After having downgraded version by version, everything works fine up until 2.9.6. From 2.9.7 the problem starts occurring.

// Latest working version
"@astrojs/node": "5.3.0",
"astro": "2.9.6"

@natemoo-re natemoo-re added the feat: error pages Related to 404 and 500 handling (scope) label Aug 16, 2023
@xriter
Copy link
Author

xriter commented Aug 18, 2023

Unfortunately the updates of Astro 2.10.10 haven't solved this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: has workaround Bug, but has workaround (priority) feat: error pages Related to 404 and 500 handling (scope) pkg: node Related to Node adapter (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants