Skip to content

CDN cannot be disabled in production #1324

@OlaAlsaker

Description

@OlaAlsaker

Version

module: 1.13.3
nuxt: 3.11.2

Nuxt configuration

export default defineNuxtConfig({
  devtools: { enabled: false },
  modules: ['@nuxtjs/sanity', '@nuxtjs/tailwindcss'],
  sanity: {
    projectId: '<removed>',
    dataset: 'production',
    apiVersion: '2022-12-30',
    useCdn: false
  },
  ssr: false,
});

Reproduction

⚠️ without a minimal reproduction we wont be able to look into your issue

Link:
[ ] https://stackblitz.com/edit/nuxt-sanity
[ ] GitHub repository

What is expected?

When useCdn is set to false in the config, we expect the client to use api.sanity.io as API-url in production (with nuxt build).

What is actually happening?

The client uses apicdn.sanity.io in production, even if useCdn is set to false. The reason can be found in this code:

if (!options.disableSmartCdn && nuxtApp.$preview) {
options.useCdn = false
}
else if (!import.meta.dev && !options.useCdn && !options.token) {
options.useCdn = true
}

The bug is in this line:

if (!import.meta.dev && !options.useCdn && !options.token) {

The !options.useCdn will return true when useCdn is set to false. This should probably be something like this:

if (!import.meta.dev && options.useCdn === undefined && !options.token) {

I tried making this change locally, and can confirm that it works like expected now.

Steps to reproduce

Additional information

Checklist

  • I have tested with the latest Nuxt version and the issue still occurs
  • I have tested with the latest module version and the issue still occurs
  • I have searched the issue tracker and this issue hasn't been reported yet

Steps to reproduce

  1. Create a basic project with Nuxt + Sanity
  2. Set useCdn to false
  3. Build the project and check the URL that is requested

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions