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

Full-static generated site 404 & then accessing asyncdata #7648

Closed
lukas-a-brand opened this issue Jul 1, 2020 · 7 comments · Fixed by #7657
Closed

Full-static generated site 404 & then accessing asyncdata #7648

lukas-a-brand opened this issue Jul 1, 2020 · 7 comments · Fixed by #7657

Comments

@lukas-a-brand
Copy link

lukas-a-brand commented Jul 1, 2020

  • nuxt: v2.13.2
  • node: v14.4.0

Reproduction

First of all let me praise you for the awesome full static mode. Although there are still a few minor things its an awesome addition!

Now to the misbehaviour :) :

my config:

    export: {
      crawler: false, // explicitly turning it off and supplying my needed routes in the routes function
      fallback: true, // It is needed for the 404 page in general as far as I understood the docs
      interval: 100, 
      async routes() {
        const routes = await getApplicationRoutes(false)
        return [
          ...routes.routes,
        ]
      },
      exclude: [/^(?=.*\btest123\b).*$/],
    }

Steps to reproduce

If you got a link somewhere to a page that is not generated, you will get 404 errors trying to fetch a payload for that page.

Seen here:
https://st.immospotter.at/components

You open the page and you will get errors for /components/media as this page does not exist yet but the link is pointing there.

Now if you go to

https://st.immospotter.at/components/media

Of course you would get a 404, but you get:
1 x 404 error for the page itself.
1 x 404 error for the try to fetch a payload for a non existing page.
1 x He still tries to do the request to fetch the data from the api, which ofc as the page doesnt exist results in another 404

What is Expected?

I am not expecting errors trying to fetch payloads of non existing pages.
I am only expecting 1 x 404 Error when i try to access the non existing page in this case /components/media.
I am expecting that he does not try to still do the api call - as he shouldnt do that anymore in full static mode as far as I understood :)

What is actually happening?

see Reproduction.

@Atinux
Copy link
Member

Atinux commented Jul 2, 2020

Hi @bstrdChronicles

Thank you for taking the time to write this bug report with the explanations.

1 x 404 error for the page itself.

This is normal

1 x 404 error for the try to fetch a payload for a non existing page.

Actually this is because it hits the SPA fallback, nice catch, I just created #7657 to fix this :)

1 x He still tries to do the request to fetch the data from the api, which ofc as the page doesnt exist results in another 404

This is normal SPA fallback behaviour since it can exists on the API but not re-generated yet.

@Atinux Atinux self-assigned this Jul 2, 2020
@pi0 pi0 closed this as completed in #7657 Jul 2, 2020
@pi0 pi0 mentioned this issue Jul 2, 2020
@lukas-a-brand
Copy link
Author

Hey Sébastien (@Atinux) :)

no problem, i really enjoy Nuxt - so want to help however I can.

Thanks for the Fix guys! :)

What would be the best way to stop the last behaviour in static production mode on pages I like, to not call the API, as I do not want people to know where my data is in some cases.
Is there an internal flag I could check against when in static production?

@Atinux
Copy link
Member

Atinux commented Jul 3, 2020

@bstrdChronicles you can use in asyncData

if (!process.dev && process.static) {
  return
}

Before calling your API, it should do the trick :)

Zekfad added a commit to Zekfad/zekfad.znnme.eu.org that referenced this issue Jul 3, 2020
@lukas-a-brand
Copy link
Author

@Atinux hmmm tried it with process.static -> but that would also not allow it in the export/generation step :)
The goal would be to allow it in the building of the pages, but not allow to access the api call once the pages are generated and the app runs.

Any idea how I could solve that? :)

@Atinux
Copy link
Member

Atinux commented Jul 3, 2020

I forgot using process.client:

if (!process.dev && process.client && process.static) {
  return
}

@lukas-a-brand
Copy link
Author

@Atinux haha yeah true, should have thought of that.
Works like a charm now :D - love it!

Thanks Sébastien!!

@Atinux
Copy link
Member

Atinux commented Jul 3, 2020

You are welcome :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants