Kaloyanes
Kaloyanes
NNuxt
Created by Kaloyanes on 1/3/2025 in #❓・help
Is there a way to create a dynamic payload for static site?
damn so there isn't a solution except for choosing a different hosting provider
26 replies
NNuxt
Created by Kaloyanes on 1/3/2025 in #❓・help
Is there a way to create a dynamic payload for static site?
which has worked in the server but not the static version
26 replies
NNuxt
Created by Kaloyanes on 1/3/2025 in #❓・help
Is there a way to create a dynamic payload for static site?
I am trying to use Notion as a CMS
26 replies
NNuxt
Created by Kaloyanes on 1/3/2025 in #❓・help
Is there a way to create a dynamic payload for static site?
my newly added code is the headers to the fetch in the client
26 replies
NNuxt
Created by Kaloyanes on 1/3/2025 in #❓・help
Is there a way to create a dynamic payload for static site?
import type {
BlockObjectResponse,
PageObjectResponse,
QueryDatabaseParameters,
} from "@notionhq/client/build/src/api-endpoints";
import { Client } from "@notionhq/client";

export const getClient = () => {
const config = useRuntimeConfig();
const token = config.public.token;

if (!token)
throw new Error(
"The NUXT_PUBLIC_NOTION_TOKEN environment variable is required",
);

return new Client({
auth: token,
fetch: async (url, options) => {
const corsOptions = {
...options,
headers: {
...options?.headers,
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
},
};

const response = await fetch(url, corsOptions);

if (response.status === 429) {
const retryAfter = response.headers.get("Retry-After");
if (retryAfter) {
const retryAfterSeconds = Number.parseInt(retryAfter, 10);
await new Promise((resolve) =>
setTimeout(resolve, retryAfterSeconds),
);
return fetch(url, corsOptions);
}
}

return response;
},
});
};

export const fetchPages = async (language: string, status = "Live") => {
const config = useRuntimeConfig();

const notionClient = getClient();

const databaseId = config.public.databaseId;
if (!databaseId) {
throw new Error(
"The NUXT_PUBLIC_NOTION_DATABASE_ID environment variable is required.",
);
}

const args: QueryDatabaseParameters = {
database_id: databaseId,
};

console.log("Fetching pages with status", status);
if (status !== "All")
args.filter = {
property: "status",
status: {
equals: status,
},
and: [{ property: "language", select: { equals: language } }],
};

return await notionClient.databases.query(args);
};
import type {
BlockObjectResponse,
PageObjectResponse,
QueryDatabaseParameters,
} from "@notionhq/client/build/src/api-endpoints";
import { Client } from "@notionhq/client";

export const getClient = () => {
const config = useRuntimeConfig();
const token = config.public.token;

if (!token)
throw new Error(
"The NUXT_PUBLIC_NOTION_TOKEN environment variable is required",
);

return new Client({
auth: token,
fetch: async (url, options) => {
const corsOptions = {
...options,
headers: {
...options?.headers,
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
},
};

const response = await fetch(url, corsOptions);

if (response.status === 429) {
const retryAfter = response.headers.get("Retry-After");
if (retryAfter) {
const retryAfterSeconds = Number.parseInt(retryAfter, 10);
await new Promise((resolve) =>
setTimeout(resolve, retryAfterSeconds),
);
return fetch(url, corsOptions);
}
}

return response;
},
});
};

export const fetchPages = async (language: string, status = "Live") => {
const config = useRuntimeConfig();

const notionClient = getClient();

const databaseId = config.public.databaseId;
if (!databaseId) {
throw new Error(
"The NUXT_PUBLIC_NOTION_DATABASE_ID environment variable is required.",
);
}

const args: QueryDatabaseParameters = {
database_id: databaseId,
};

console.log("Fetching pages with status", status);
if (status !== "All")
args.filter = {
property: "status",
status: {
equals: status,
},
and: [{ property: "language", select: { equals: language } }],
};

return await notionClient.databases.query(args);
};
26 replies
NNuxt
Created by Kaloyanes on 1/3/2025 in #❓・help
Is there a way to create a dynamic payload for static site?
now the new problem is that the cors doesn't work
26 replies
NNuxt
Created by Kaloyanes on 1/3/2025 in #❓・help
Is there a way to create a dynamic payload for static site?
alright
26 replies
NNuxt
Created by Kaloyanes on 1/3/2025 in #❓・help
Is there a way to create a dynamic payload for static site?
Well when I do call it from there it gives me the error that there isn't a nuxt context
26 replies
NNuxt
Created by Kaloyanes on 1/3/2025 in #❓・help
Is there a way to create a dynamic payload for static site?
well from the utils i think its not nuxt context
26 replies
NNuxt
Created by Kaloyanes on 1/3/2025 in #❓・help
Is there a way to create a dynamic payload for static site?
will try to use the runtime config from the blog page and just redirect it to the utils function with a variable
26 replies
NNuxt
Created by Kaloyanes on 1/3/2025 in #❓・help
Is there a way to create a dynamic payload for static site?
doesnt give me to access them using the runtime config on utils function dunno
26 replies
NNuxt
Created by Kaloyanes on 1/3/2025 in #❓・help
Is there a way to create a dynamic payload for static site?
And when i nuxi generate it doesnt create api routes because it's static. In my api i am just redirecting to a utils function because of the env variables. I can't access them on the client side
26 replies
NNuxt
Created by Kaloyanes on 1/3/2025 in #❓・help
Is there a way to create a dynamic payload for static site?
It's by my employer that i use their hosting provider : (
26 replies
NNuxt
Created by Kaloyanes on 4/15/2024 in #❓・help
Why is the Nuxt dev server so slow?
after all you were right. Thanks
16 replies
NNuxt
Created by Kaloyanes on 4/15/2024 in #❓・help
Why is the Nuxt dev server so slow?
omfg found it. It was the /dashboard route page not the /dashboard/orders/all page and it had a promise that was trying to connect to the profile document on firebase : / damn. Thank you guys
16 replies
NNuxt
Created by Kaloyanes on 4/15/2024 in #❓・help
Why is the Nuxt dev server so slow?
so yea
16 replies
NNuxt
Created by Kaloyanes on 4/15/2024 in #❓・help
Why is the Nuxt dev server so slow?
like /dashboard/orders/all
16 replies
NNuxt
Created by Kaloyanes on 4/15/2024 in #❓・help
Why is the Nuxt dev server so slow?
but this is the name of the route
16 replies
NNuxt
Created by Kaloyanes on 4/15/2024 in #❓・help
Why is the Nuxt dev server so slow?
No description
16 replies
NNuxt
Created by Kaloyanes on 4/15/2024 in #❓・help
Why is the Nuxt dev server so slow?
No description
16 replies