@devite/nuxt-sanity 2.4.1 → 2.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.d.mts CHANGED
@@ -10,7 +10,16 @@ type ModuleOptions = ClientConfig & {
10
10
  /** @default { cachingEnabled: true, cacheBaseUrl: "http://localhost:3000", assetEndpoint: "/_sanity/cache/asset", queryEndpoint: "/_sanity/cache/query", webhookEndpoint: "/_sanity/cache/invalidate" } */
11
11
  minimalClient?: boolean | {
12
12
  cachingEnabled?: boolean;
13
- cacheBaseUrl?: string;
13
+ /**
14
+ * This is the base url for fetching data after hydration
15
+ * @default 'http://localhost:3000'
16
+ */
17
+ cacheClientBaseUrl?: string;
18
+ /**
19
+ * This is the base url for fetching data during SSR
20
+ * @default 'http://localhost:3000'
21
+ */
22
+ cacheServerBaseUrl?: string;
14
23
  assetEndpoint?: string;
15
24
  queryEndpoint?: string;
16
25
  webhookEndpoint?: string;
package/dist/module.d.ts CHANGED
@@ -10,7 +10,16 @@ type ModuleOptions = ClientConfig & {
10
10
  /** @default { cachingEnabled: true, cacheBaseUrl: "http://localhost:3000", assetEndpoint: "/_sanity/cache/asset", queryEndpoint: "/_sanity/cache/query", webhookEndpoint: "/_sanity/cache/invalidate" } */
11
11
  minimalClient?: boolean | {
12
12
  cachingEnabled?: boolean;
13
- cacheBaseUrl?: string;
13
+ /**
14
+ * This is the base url for fetching data after hydration
15
+ * @default 'http://localhost:3000'
16
+ */
17
+ cacheClientBaseUrl?: string;
18
+ /**
19
+ * This is the base url for fetching data during SSR
20
+ * @default 'http://localhost:3000'
21
+ */
22
+ cacheServerBaseUrl?: string;
14
23
  assetEndpoint?: string;
15
24
  queryEndpoint?: string;
16
25
  webhookEndpoint?: string;
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
- "version": "2.4.1",
3
+ "version": "2.4.3",
4
4
  "configKey": "sanity",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
package/dist/module.mjs CHANGED
@@ -3,7 +3,7 @@ import { defineNuxtModule, createResolver, addPlugin, addServerHandler, addImpor
3
3
  import defu from 'defu';
4
4
 
5
5
  const name = "@devite/nuxt-sanity";
6
- const version = "2.4.1";
6
+ const version = "2.4.3";
7
7
 
8
8
  const CONFIG_KEY = "sanity";
9
9
  const module = defineNuxtModule({
@@ -21,7 +21,8 @@ const module = defineNuxtModule({
21
21
  dataset: options.dataset || "production",
22
22
  minimalClient: options.minimalClient !== false ? defu(options.minimalClient, {
23
23
  cachingEnabled: true,
24
- cacheBaseUrl: "http://localhost:3000",
24
+ cacheClientBaseUrl: "http://localhost:3000",
25
+ cacheServerBaseUrl: "http://localhost:3000",
25
26
  assetEndpoint: "/_sanity/cache/asset",
26
27
  queryEndpoint: "/_sanity/cache/query",
27
28
  webhookEndpoint: "/_sanity/cache/invalidate"
@@ -39,7 +39,8 @@ class MinimalSanityClient extends SanityClient {
39
39
  const isEligibleForGetRequest = byteLength <= 9e3;
40
40
  const minimalClientConfig = typeof this.config.minimalClient === "object" ? this.config.minimalClient : {};
41
41
  const useCache = minimalClientConfig.cachingEnabled && isEligibleForGetRequest;
42
- const requestUrl = useCache && minimalClientConfig.cacheBaseUrl ? minimalClientConfig.cacheBaseUrl + minimalClientConfig.queryEndpoint : `https://${this.config.projectId}.${this.config.useCdn && isEligibleForGetRequest ? API_CDN_HOST : API_HOST}${this.queryPath}`;
42
+ const cacheBaseUrl = import.meta.client ? minimalClientConfig.cacheClientBaseUrl : minimalClientConfig.cacheServerBaseUrl;
43
+ const requestUrl = useCache && cacheBaseUrl ? cacheBaseUrl + minimalClientConfig.queryEndpoint : `https://${this.config.projectId}.${this.config.useCdn && isEligibleForGetRequest ? API_CDN_HOST : API_HOST}${this.queryPath}`;
43
44
  return (await $fetch(requestUrl + queryString, {
44
45
  ...this.fetchOptions,
45
46
  method: isEligibleForGetRequest ? "GET" : "POST",
@@ -12,10 +12,11 @@
12
12
  import { computed, type ComputedRef } from 'vue'
13
13
  import type { ImageAsset } from '@sanity/types'
14
14
  import type { GlobalSEO, Home, NotFound, Page } from '@devite/nuxt-sanity'
15
+ import { setResponseStatus } from 'h3'
15
16
  import { IMAGE_WITHOUT_PREVIEW_PROJECTION } from '../utils/projections'
16
17
  import { useSanityQuery } from '../composables/useSanityQuery'
17
18
  import { groq } from '../utils/groq'
18
- import { useHead, useRoute, useRuntimeConfig, useSeoMeta } from '#imports'
19
+ import { useHead, useRoute, useRuntimeConfig, useSeoMeta, useRequestEvent } from '#imports'
19
20
 
20
21
  const path = useRoute().path
21
22
  const groqFilter = path === '/' ? '_type == "home"' : `_type == "page" && slug.current == $slug`
@@ -24,6 +25,13 @@ const { data: sanityData } = await useSanityQuery<Home | Page | NotFound>(
24
25
  { slug: path.substring(1) },
25
26
  )
26
27
 
28
+ if (sanityData.value?._type === 'notFound' && import.meta.server) {
29
+ const event = useRequestEvent()
30
+
31
+ if (event)
32
+ setResponseStatus(event, 404)
33
+ }
34
+
27
35
  const { baseURL } = useRuntimeConfig().public
28
36
  const seo = computed(() => sanityData.value?.seo)
29
37
  const url = computed(
@@ -6,11 +6,11 @@ export const getImage = (src, { modifiers = {} } = {}, ctx) => {
6
6
  const sanityConfig = useRuntimeConfig().public.sanity;
7
7
  const minimalClientConfig = sanityConfig.minimalClient;
8
8
  const useCaching = typeof minimalClientConfig === "object" && minimalClientConfig.cachingEnabled;
9
- if (useCaching && minimalClientConfig.cacheBaseUrl && !useSanityVisualEditingState().enabled) {
9
+ if (useCaching && minimalClientConfig.cacheClientBaseUrl && !useSanityVisualEditingState().enabled) {
10
10
  const params = new URLSearchParams();
11
11
  params.set("src", src);
12
12
  params.set("modifiers", JSON.stringify(modifiers));
13
- return { url: joinURL(minimalClientConfig.cacheBaseUrl, minimalClientConfig.assetEndpoint + `?${params.toString()}`) };
13
+ return { url: joinURL(minimalClientConfig.cacheClientBaseUrl, minimalClientConfig.assetEndpoint + `?${params.toString()}`) };
14
14
  }
15
15
  return getSanityImage(src, { modifiers, projectId: sanityConfig.projectId, dataset: sanityConfig.dataset }, ctx);
16
16
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devite/nuxt-sanity",
3
- "version": "2.4.1",
3
+ "version": "2.4.3",
4
4
  "description": "Advanced Sanity integration for Nuxt.js.",
5
5
  "repository": "devite-io/nuxt-sanity",
6
6
  "license": "MIT",