* 🚀 refactor: simplify deployment process in workflow file * 🚀 chore: add IMAGE_NAME to GITHUB_ENV for deployment workflow * ✨ chore: simplify deployment logging in workflow file * 🚀 fix: correct container name in deployment script logic * 🚀 refactor: rename job and streamline deployment steps * Update README.md * ✨ fix: prevent multiple form submissions in Contact component * ✨ feat: honeypot and timestamp checks to form submission * ✨ refactor: simplify contact form and improve UI elements * ✨ feat: add responsive masonry layout for projects display * ✨ style: Update project title size and improve layout visibility * ✨ fix: remove unnecessary test assertions and improve act usage * ✨ chore: add @types/react-responsive-masonry package fixing with this import error on building * ✨ chore: remove unused dev dependencies from package-lock.json * ✨ refactor: update environment variable usage and add caching * ✨ refactor: update environment variables and dependencies * ✨ chore: streamline Dockerfile and remove redundant steps
61 lines
1.5 KiB
TypeScript
61 lines
1.5 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import http from "http";
|
|
import fetch from "node-fetch";
|
|
import NodeCache from "node-cache";
|
|
|
|
export const runtime = "nodejs"; // Force Node runtime
|
|
|
|
const GHOST_API_URL = process.env.GHOST_API_URL;
|
|
const GHOST_API_KEY = process.env.GHOST_API_KEY;
|
|
const cache = new NodeCache({ stdTTL: 300 }); // Cache für 5 Minuten
|
|
|
|
type GhostPost = {
|
|
slug: string;
|
|
id: string;
|
|
title: string;
|
|
feature_image: string;
|
|
visibility: string;
|
|
published_at: string;
|
|
updated_at: string;
|
|
html: string;
|
|
reading_time: number;
|
|
meta_description: string;
|
|
};
|
|
|
|
type GhostPostsResponse = {
|
|
posts: Array<GhostPost>;
|
|
};
|
|
|
|
export async function GET() {
|
|
const cacheKey = "ghostPosts";
|
|
const cachedPosts = cache.get<GhostPostsResponse>(cacheKey);
|
|
|
|
if (cachedPosts) {
|
|
return NextResponse.json(cachedPosts);
|
|
}
|
|
|
|
try {
|
|
const agent = new http.Agent({ keepAlive: true });
|
|
const response = await fetch(
|
|
`${GHOST_API_URL}/ghost/api/content/posts/?key=${GHOST_API_KEY}&limit=all`,
|
|
{ agent: agent as unknown as undefined }
|
|
);
|
|
const posts: GhostPostsResponse = await response.json() as GhostPostsResponse;
|
|
|
|
if (!posts || !posts.posts) {
|
|
console.error("Invalid posts data");
|
|
return NextResponse.json([]);
|
|
}
|
|
|
|
cache.set(cacheKey, posts); // Daten im Cache speichern
|
|
|
|
return NextResponse.json(posts);
|
|
} catch (error) {
|
|
console.error("Failed to fetch posts from Ghost:", error);
|
|
return NextResponse.json(
|
|
{ error: "Failed to fetch projects" },
|
|
{ status: 500 },
|
|
);
|
|
}
|
|
}
|