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

Support for file & payload output without folders for prerendered/SSG pages (Cloudflare Pages 308 problem) #1552

Closed
1 task
lukas-a-brand opened this issue Aug 8, 2023 · 1 comment

Comments

@lukas-a-brand
Copy link

lukas-a-brand commented Aug 8, 2023

Hello,

I stumbled upon an issue when porting a website for hosting on Cloudflare pages.

Based on your output directory format, e.g., if you have foo/index.html, your request will be served at /foo/, whereas if you have /foo.html, it'll be served at /foo.

Cloudflare pages then proceed to do 308 redirects for any non-trailing slash URL, which might (in my case for sure) not be intended.

I talked with @danielroe about this, and he asked me to raise this here, as it would probably need to be addressed in Nitro.
He also went on to give an idea for a workaround, which works out great! (:

export default defineNuxtConfig({
  nitro: {
    hooks: {
      // In the case of Cloudflare Pages, non-trailing slash pages cause 308 redirects, these are caused by the output file structure. /foo/index.html > /foo.html
      'prerender:generate' (route) {
        if (route.fileName) {
          route.fileName = route.fileName.replace(
            /(\w+)\/index.html$/,
            '$1.html'
          )
        }
      }
    }
    }
  }
})

Additional information

  • Would you be willing to help implement this feature?
@pi0
Copy link
Member

pi0 commented Nov 8, 2024

It is possible to use prerender.autoSubfolderIndex: false config to avoid folder creation. (#1676)

@pi0 pi0 closed this as completed Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants