Switch from ISR to full SSR + add comprehensive logging
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 28s

This commit is contained in:
Adrian Miesikowski 2026-02-10 20:56:59 +01:00
parent a02add2025
commit 122d151182
8 changed files with 58 additions and 11 deletions

View File

@ -37,6 +37,10 @@ COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# Copy entrypoint script
COPY --chown=nextjs:nodejs docker-entrypoint.sh ./
RUN chmod +x docker-entrypoint.sh
USER nextjs USER nextjs
EXPOSE 3000 EXPOSE 3000
@ -44,4 +48,4 @@ EXPOSE 3000
ENV PORT=3000 ENV PORT=3000
ENV HOSTNAME="0.0.0.0" ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"] CMD ["./docker-entrypoint.sh"]

View File

@ -4,11 +4,14 @@ import { getAllPosts } from "@/lib/blog";
export const dynamic = "force-dynamic"; export const dynamic = "force-dynamic";
export async function GET(request: Request) { export async function GET(request: Request) {
console.log("[API] 🌐 GET /api/blog - Request received");
try { try {
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);
const category = searchParams.get("category") as "case-study" | "blog" | null; const category = searchParams.get("category") as "case-study" | "blog" | null;
console.log("[API] 📋 Parameters:", { category });
const posts = await getAllPosts(category || undefined); const posts = await getAllPosts(category || undefined);
console.log("[API] ✅ Response ready:", { count: posts.length });
return NextResponse.json({ return NextResponse.json({
success: true, success: true,
@ -16,7 +19,7 @@ export async function GET(request: Request) {
count: posts.length, count: posts.length,
}); });
} catch (error) { } catch (error) {
console.error("API Error:", error); console.error("[API] ❌ Error:", error);
return NextResponse.json({ success: false, error: "Failed to fetch posts" }, { status: 500 }); return NextResponse.json({ success: false, error: "Failed to fetch posts" }, { status: 500 });
} }
} }

View File

@ -3,8 +3,8 @@ import { notFound } from "next/navigation";
import { getAllPosts, getPostBySlug } from "@/lib/blog"; import { getAllPosts, getPostBySlug } from "@/lib/blog";
import BlogPost from "@/components/BlogPost"; import BlogPost from "@/components/BlogPost";
// ISR: Revalidate every 60 seconds // Force SSR - always fetch fresh data
export const revalidate = 60; export const dynamic = 'force-dynamic';
// Generate static params for all blog posts // Generate static params for all blog posts
export async function generateStaticParams() { export async function generateStaticParams() {

View File

@ -2,8 +2,8 @@ import type { Metadata } from "next";
import { getAllPosts } from "@/lib/blog"; import { getAllPosts } from "@/lib/blog";
import BlogList from "@/components/BlogList"; import BlogList from "@/components/BlogList";
// Revalidate every 60 seconds // Force SSR - always fetch fresh data
export const revalidate = 60; export const dynamic = 'force-dynamic';
export const metadata: Metadata = { export const metadata: Metadata = {
title: "Blog AI i Case Studies — SZMYT AI Labs", title: "Blog AI i Case Studies — SZMYT AI Labs",

View File

@ -10,8 +10,8 @@ import ScrollReveal from "@/components/ScrollReveal";
import FeaturedBlog from "@/components/FeaturedBlog"; import FeaturedBlog from "@/components/FeaturedBlog";
import { getFeaturedPosts } from "@/lib/blog"; import { getFeaturedPosts } from "@/lib/blog";
// Revalidate every 60 seconds // Force SSR - always fetch fresh data
export const revalidate = 60; export const dynamic = 'force-dynamic';
export const metadata: Metadata = { export const metadata: Metadata = {
title: "Sztuczna Inteligencja dla Firm — Wdrożenie AI w Biznesie | SZMYT AI Labs", title: "Sztuczna Inteligencja dla Firm — Wdrożenie AI w Biznesie | SZMYT AI Labs",

21
docker-entrypoint.sh Normal file
View File

@ -0,0 +1,21 @@
#!/bin/sh
echo "========================================="
echo "🚀 Starting sztucznainteligencjadlafirm container"
echo "========================================="
echo ""
echo "📦 Environment Variables:"
echo " NODE_ENV: ${NODE_ENV}"
echo " PORT: ${PORT}"
echo " MONGODB_URI: ${MONGODB_URI}"
echo ""
echo "🔍 Container Info:"
echo " Hostname: $(hostname)"
echo " User: $(whoami)"
echo " PWD: $(pwd)"
echo ""
echo "========================================="
echo ""
# Start Next.js server
exec node server.js

View File

@ -56,17 +56,21 @@ function serializePost(post: any): BlogPost {
export async function getAllPosts( export async function getAllPosts(
category?: "case-study" | "blog", category?: "case-study" | "blog",
): Promise<BlogPost[]> { ): Promise<BlogPost[]> {
console.log("[Blog] 📚 Fetching posts...", { category: category || "all" });
try { try {
const client = await clientPromise; const client = await clientPromise;
const db = client.db(DB_NAME); const db = client.db(DB_NAME);
const query = category ? { category } : {}; const query = category ? { category } : {};
console.log("[Blog] 🔍 Query:", query);
const posts = await db const posts = await db
.collection<BlogPost>(COLLECTION_NAME) .collection<BlogPost>(COLLECTION_NAME)
.find(query) .find(query)
.sort({ publishedAt: -1 }) .sort({ publishedAt: -1 })
.toArray(); .toArray();
console.log("[Blog] ✅ Posts fetched:", posts.length);
return posts.map(serializePost); return posts.map(serializePost);
} catch (error) { } catch (error) {
console.error("Database Error:", error); console.error("Database Error:", error);

View File

@ -1,9 +1,13 @@
import { MongoClient } from "mongodb"; import { MongoClient } from "mongodb";
// Production MongoDB connection // MongoDB connection from environment or fallback
const uri = const uri = process.env.MONGODB_URI ||
"mongodb://mo1124_ai_web:~4nfR5EA)3%C2%A3%40@mongo76.mydevil.net:27017/mo1124_ai_web?authSource=mo1124_ai_web"; "mongodb://mo1124_ai_web:~4nfR5EA)3%C2%A3%40@mongo76.mydevil.net:27017/mo1124_ai_web?authSource=mo1124_ai_web";
console.log("[MongoDB] 🔧 Initializing connection...");
console.log("[MongoDB] 📍 URI:", uri.replace(/:\/\/([^:]+):([^@]+)@/, "://<username>:<password>@"));
console.log("[MongoDB] 🌍 Environment:", process.env.NODE_ENV);
// Use global variable to preserve connection across HMR in development // Use global variable to preserve connection across HMR in development
let globalWithMongo = global as typeof globalThis & { let globalWithMongo = global as typeof globalThis & {
_mongoClientPromise?: Promise<MongoClient>; _mongoClientPromise?: Promise<MongoClient>;
@ -12,8 +16,19 @@ let globalWithMongo = global as typeof globalThis & {
let clientPromise: Promise<MongoClient>; let clientPromise: Promise<MongoClient>;
if (!globalWithMongo._mongoClientPromise) { if (!globalWithMongo._mongoClientPromise) {
console.log("[MongoDB] 🔌 Creating new connection...");
const client = new MongoClient(uri); const client = new MongoClient(uri);
globalWithMongo._mongoClientPromise = client.connect(); globalWithMongo._mongoClientPromise = client.connect()
.then((client) => {
console.log("[MongoDB] ✅ Connected successfully");
return client;
})
.catch((error) => {
console.error("[MongoDB] ❌ Connection failed:", error.message);
throw error;
});
} else {
console.log("[MongoDB] ♻️ Reusing existing connection");
} }
clientPromise = globalWithMongo._mongoClientPromise; clientPromise = globalWithMongo._mongoClientPromise;