nuxt / content

The file-based CMS for your Nuxt application, powered by Markdown and Vue components.
https://content.nuxt.com
MIT License
3.15k stars 630 forks source link

Deploy for Cloudflare Pages (nuxt content ssr:false) #1736

Open hermesalvesbr opened 1 year ago

hermesalvesbr commented 1 year ago

Environment

Nuxi 3.0.0                                                                                                                                                                          17:46:59
                                                                                                                                                                                    17:47:00
RootDir: /nuxt/content/                                                                                                                                              17:47:00
Nuxt project info:                                                                                                                                                                  17:47:00

------------------------------
- Operating System: `Linux`
- Node Version:     `v18.7.0`
- Nuxt Version:     `3.0.0`
- Nitro Version:    `1.0.0`
- Package Manager:  `yarn@1.22.19`
- Builder:          `vite`
- User Config:      `ssr`, `nitro`, `runtimeConfig`, `modules`, `directus`, `content`
- Runtime Modules:  `@nuxt/content@2.2.2`, `@nuxtjs/tailwindcss@6.1.3`, `nuxt-directus@3.2.2`
- Build Modules:    `-`
------------------------------

Reproduction

I'm trying to deploy the nuxt content project for cloudflare pages, i have another project with Nuxt v3, but without nuxt content.

export default defineNuxtConfig({
  ssr: false,
  nitro: {
    preset: "service-worker",
  },
  modules: ["@nuxt/content", "@nuxtjs/tailwindcss", "nuxt-directus"],
  directus: {
    url: process.env.NUXT_API_URL,
    token: process.env.NUXT_API_SECRET,
  },
  content: {
    highlight: {
      theme: "light-plus",
    },
    documentDriven: false,
    base: '/_content'
  },
})

I have tried various nuxt configs, with preset service worker also base path for /content, but, didn´t work.

Describe the bug

I put online for some analysis: https://alpha.bodoco-site.pages.dev/noticias/

Uncaught (in promise) TypeError: Failed to register a ServiceWorker for scope ('https://alpha.bodoco-site.pages.dev/') with script ('https://alpha.bodoco-site.pages.dev/sw.js'): A bad HTTP response code (404) was received when fetching the script.

https://content.nuxtjs.org/guide/deploy/static-hosting https://content.nuxtjs.org/api/configuration/

With configuration base for /_content/ they show me 404 for this url https://alpha.bodoco-site.pages.dev/api/_content/navigation?_params={}

Without base show me 404 for path route.

Additional context

No response

Logs

Failed to load resource: the server responded with a status of 404 ()
farnabaz commented 1 year ago

In order to make it work with CF workers you need to use nuxi build instead of generate. Generate command will not create service worker. It seems that you used generate to deploy in CF Workers.

Try using yarn nuxi build. Then you can confirm that sw.js is exists inside .output/public directory

hermesalvesbr commented 1 year ago

Yes, with CF Workers, work's fine. But i can't to use content with CF PAges?

farnabaz commented 1 year ago

Oh my bad, I meant CF Pages Just test it with yarn nuxi build, it should solve the issue