full upgrade to dev
This commit is contained in:
@@ -7,9 +7,9 @@ async function getFetch() {
|
||||
try {
|
||||
const mod = await import("node-fetch");
|
||||
// support both CJS and ESM interop
|
||||
return (mod as any).default ?? mod;
|
||||
} catch (err) {
|
||||
return (globalThis as any).fetch;
|
||||
return (mod as { default: unknown }).default ?? mod;
|
||||
} catch (_err) {
|
||||
return (globalThis as unknown as { fetch: unknown }).fetch;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,9 +49,10 @@ export async function GET() {
|
||||
const fetchFn = await getFetch();
|
||||
const response = await fetchFn(
|
||||
`${GHOST_API_URL}/ghost/api/content/posts/?key=${GHOST_API_KEY}&limit=all`,
|
||||
{ agent: agent as unknown as undefined }
|
||||
{ agent: agent as unknown as undefined },
|
||||
);
|
||||
const posts: GhostPostsResponse = await response.json() as GhostPostsResponse;
|
||||
const posts: GhostPostsResponse =
|
||||
(await response.json()) as GhostPostsResponse;
|
||||
|
||||
if (!posts || !posts.posts) {
|
||||
console.error("Invalid posts data");
|
||||
|
||||
@@ -13,22 +13,28 @@ export async function GET(req: NextRequest) {
|
||||
|
||||
try {
|
||||
// Try global fetch first, fall back to node-fetch if necessary
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let response: any;
|
||||
try {
|
||||
if (typeof (globalThis as any).fetch === 'function') {
|
||||
response = await (globalThis as any).fetch(url);
|
||||
if (
|
||||
typeof (globalThis as unknown as { fetch: unknown }).fetch ===
|
||||
"function"
|
||||
) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
response = await (globalThis as unknown as { fetch: any }).fetch(url);
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (_e) {
|
||||
response = undefined;
|
||||
}
|
||||
|
||||
if (!response || typeof response.ok === 'undefined' || !response.ok) {
|
||||
if (!response || typeof response.ok === "undefined" || !response.ok) {
|
||||
try {
|
||||
const mod = await import('node-fetch');
|
||||
const nodeFetch = (mod as any).default ?? mod;
|
||||
response = await nodeFetch(url);
|
||||
const mod = await import("node-fetch");
|
||||
const nodeFetch = (mod as { default: unknown }).default ?? mod;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
response = await (nodeFetch as any)(url);
|
||||
} catch (err) {
|
||||
console.error('Failed to fetch image:', err);
|
||||
console.error("Failed to fetch image:", err);
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch image" },
|
||||
{ status: 500 },
|
||||
@@ -37,7 +43,9 @@ export async function GET(req: NextRequest) {
|
||||
}
|
||||
|
||||
if (!response || !response.ok) {
|
||||
throw new Error(`Failed to fetch image: ${response?.statusText ?? 'no response'}`);
|
||||
throw new Error(
|
||||
`Failed to fetch image: ${response?.statusText ?? "no response"}`,
|
||||
);
|
||||
}
|
||||
|
||||
const contentType = response.headers.get("content-type");
|
||||
|
||||
@@ -15,40 +15,52 @@ export async function GET(request: Request) {
|
||||
|
||||
try {
|
||||
// Debug: show whether fetch is present/mocked
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('DEBUG fetch in fetchProject:', typeof (globalThis as any).fetch, 'globalIsMock:', !!(globalThis as any).fetch?._isMockFunction);
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
console.log(
|
||||
"DEBUG fetch in fetchProject:",
|
||||
typeof (globalThis as any).fetch,
|
||||
"globalIsMock:",
|
||||
!!(globalThis as any).fetch?._isMockFunction,
|
||||
);
|
||||
|
||||
// Try global fetch first (as tests often mock it). If it fails or returns undefined,
|
||||
// fall back to dynamically importing node-fetch.
|
||||
let response: any;
|
||||
|
||||
if (typeof (globalThis as any).fetch === 'function') {
|
||||
if (typeof (globalThis as any).fetch === "function") {
|
||||
try {
|
||||
response = await (globalThis as any).fetch(
|
||||
`${GHOST_API_URL}/ghost/api/content/posts/slug/${slug}/?key=${GHOST_API_KEY}`,
|
||||
);
|
||||
} catch (e) {
|
||||
} catch (_e) {
|
||||
response = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
if (!response || typeof response.ok === 'undefined') {
|
||||
if (!response || typeof response.ok === "undefined") {
|
||||
try {
|
||||
const mod = await import('node-fetch');
|
||||
const mod = await import("node-fetch");
|
||||
const nodeFetch = (mod as any).default ?? mod;
|
||||
response = await nodeFetch(
|
||||
response = await (nodeFetch as any)(
|
||||
`${GHOST_API_URL}/ghost/api/content/posts/slug/${slug}/?key=${GHOST_API_KEY}`,
|
||||
);
|
||||
} catch (err) {
|
||||
} catch (_err) {
|
||||
response = undefined;
|
||||
}
|
||||
}
|
||||
/* eslint-enable @typescript-eslint/no-explicit-any */
|
||||
|
||||
// Debug: inspect the response returned from the fetch
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('DEBUG fetch response:', response);
|
||||
|
||||
// Debug: inspect the response returned from the fetch
|
||||
|
||||
console.log("DEBUG fetch response:", response);
|
||||
|
||||
if (!response || !response.ok) {
|
||||
throw new Error(`Failed to fetch post: ${response?.statusText ?? 'no response'}`);
|
||||
throw new Error(
|
||||
`Failed to fetch post: ${response?.statusText ?? "no response"}`,
|
||||
);
|
||||
}
|
||||
|
||||
const post = await response.json();
|
||||
|
||||
@@ -14,7 +14,6 @@ export const runtime = "nodejs"; // Force Node runtime
|
||||
|
||||
// Read Ghost API config at runtime, tests may set env vars in beforeAll
|
||||
|
||||
|
||||
// Funktion, um die XML für die Sitemap zu generieren
|
||||
function generateXml(sitemapRoutes: { url: string; lastModified: string }[]) {
|
||||
const xmlHeader = '<?xml version="1.0" encoding="UTF-8"?>';
|
||||
@@ -63,7 +62,7 @@ export async function GET() {
|
||||
];
|
||||
|
||||
// In test environment we can short-circuit and use a mocked posts payload
|
||||
if (process.env.NODE_ENV === 'test' && process.env.GHOST_MOCK_POSTS) {
|
||||
if (process.env.NODE_ENV === "test" && process.env.GHOST_MOCK_POSTS) {
|
||||
const mockData = JSON.parse(process.env.GHOST_MOCK_POSTS);
|
||||
const projects = (mockData as ProjectsData).posts || [];
|
||||
|
||||
@@ -73,7 +72,7 @@ export async function GET() {
|
||||
url: `${baseUrl}/projects/${project.slug}`,
|
||||
lastModified,
|
||||
priority: 0.8,
|
||||
changeFreq: 'monthly',
|
||||
changeFreq: "monthly",
|
||||
};
|
||||
});
|
||||
|
||||
@@ -81,43 +80,46 @@ export async function GET() {
|
||||
const xml = generateXml(allRoutes);
|
||||
|
||||
// For tests return a plain object so tests can inspect `.body` easily
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
return { body: xml, headers: { 'Content-Type': 'application/xml' } } as any;
|
||||
if (process.env.NODE_ENV === "test") {
|
||||
return {
|
||||
body: xml,
|
||||
headers: { "Content-Type": "application/xml" },
|
||||
};
|
||||
}
|
||||
|
||||
return new NextResponse(xml, {
|
||||
headers: { 'Content-Type': 'application/xml' },
|
||||
headers: { "Content-Type": "application/xml" },
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
// Debug: show whether fetch is present/mocked
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('DEBUG fetch in sitemap API:', typeof (globalThis as any).fetch, 'globalIsMock:', !!(globalThis as any).fetch?._isMockFunction);
|
||||
|
||||
// Try global fetch first (tests may mock global.fetch)
|
||||
let response: any;
|
||||
let response: Response | undefined;
|
||||
|
||||
try {
|
||||
if (typeof (globalThis as any).fetch === 'function') {
|
||||
response = await (globalThis as any).fetch(
|
||||
if (typeof globalThis.fetch === "function") {
|
||||
response = await globalThis.fetch(
|
||||
`${process.env.GHOST_API_URL}/ghost/api/content/posts/?key=${process.env.GHOST_API_KEY}&limit=all`,
|
||||
);
|
||||
// Debug: inspect the result
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('DEBUG sitemap global fetch returned:', response);
|
||||
|
||||
console.log("DEBUG sitemap global fetch returned:", response);
|
||||
}
|
||||
} catch (e) {
|
||||
} catch (_e) {
|
||||
response = undefined;
|
||||
}
|
||||
|
||||
if (!response || typeof response.ok === 'undefined' || !response.ok) {
|
||||
if (!response || typeof response.ok === "undefined" || !response.ok) {
|
||||
try {
|
||||
const mod = await import('node-fetch');
|
||||
const nodeFetch = (mod as any).default ?? mod;
|
||||
const mod = await import("node-fetch");
|
||||
const nodeFetch = mod.default ?? mod;
|
||||
response = await nodeFetch(
|
||||
`${process.env.GHOST_API_URL}/ghost/api/content/posts/?key=${process.env.GHOST_API_KEY}&limit=all`,
|
||||
);
|
||||
} catch (err) {
|
||||
console.log('Failed to fetch posts from Ghost:', err);
|
||||
console.log("Failed to fetch posts from Ghost:", err);
|
||||
return new NextResponse(generateXml(staticRoutes), {
|
||||
headers: { "Content-Type": "application/xml" },
|
||||
});
|
||||
@@ -125,13 +127,16 @@ export async function GET() {
|
||||
}
|
||||
|
||||
if (!response || !response.ok) {
|
||||
console.error(`Failed to fetch posts: ${response?.statusText ?? 'no response'}`);
|
||||
console.error(
|
||||
`Failed to fetch posts: ${response?.statusText ?? "no response"}`,
|
||||
);
|
||||
return new NextResponse(generateXml(staticRoutes), {
|
||||
headers: { "Content-Type": "application/xml" },
|
||||
});
|
||||
}
|
||||
|
||||
const projectsData = (await response.json()) as ProjectsData;
|
||||
|
||||
const projects = projectsData.posts;
|
||||
|
||||
// Dynamische Projekt-Routen generieren
|
||||
|
||||
Reference in New Issue
Block a user