From af35a071a731e973e833becae0184c22bc991067 Mon Sep 17 00:00:00 2001 From: Denshooter Date: Wed, 12 Feb 2025 17:23:05 +0100 Subject: [PATCH 1/2] refactor: clean up project details URL handling Removes unnecessary TypeScript error suppression for window object usage in the ProjectDetails component. This change improves code clarity and maintains functionality by ensuring the project data is removed from the URL without reloading the page. --- app/Projects/[slug]/page.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/Projects/[slug]/page.tsx b/app/Projects/[slug]/page.tsx index 9724d06..ebab8db 100644 --- a/app/Projects/[slug]/page.tsx +++ b/app/Projects/[slug]/page.tsx @@ -45,12 +45,9 @@ const ProjectDetails = () => { if (projectData) { setProject(JSON.parse(projectData as string)); // Remove the project data from the URL without reloading the page - // @ts-expect-error window is defined if (typeof window !== "undefined") { - // @ts-expect-error window is defined const url = new URL(window.location.href); url.searchParams.delete("project"); - // @ts-expect-error window is defined window.history.replaceState({}, "", url.toString()); } } else { From b87b1d6237e7952b3273932b3f2702104bf27273 Mon Sep 17 00:00:00 2001 From: Denshooter Date: Wed, 12 Feb 2025 17:30:31 +0100 Subject: [PATCH 2/2] refactor: use environment variable for GHOST_API_KEY Replace hardcoded GHOST_API_KEY with process.env.GHOST_API_KEY in API routes to enhance security. Update Docker commands in the CI workflow to pass the GHOST_API_KEY as an environment variable. Add GHOST_API_KEY to the Next.js configuration for consistent access across the application. --- .github/workflows/main.yml | 24 ++++++++++++++---------- app/api/fetchAllProjects/route.tsx | 2 +- app/api/fetchProject/route.tsx | 2 +- next.config.ts | 4 +++- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 39ce457..e05ee13 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,34 +39,38 @@ jobs: IMAGE_NAME="my-nextjs-app:$DEPLOY_ENV" NEW_CONTAINER_NAME="$CONTAINER_NAME-new" - # Entferne vorhandenen temporären Container, falls vorhanden + # Remove existing temporary container, if any if [ "$(docker ps -aq -f name=$NEW_CONTAINER_NAME)" ]; then echo "Removing existing new container ($NEW_CONTAINER_NAME)..." docker rm -f "$NEW_CONTAINER_NAME" || true fi - # Starte den neuen Container auf einem temporären internen Port - docker run -d --name "$NEW_CONTAINER_NAME" -p 40000:3000 $IMAGE_NAME + # Start the new container on a temporary internal port + docker run -d --name "$NEW_CONTAINER_NAME" -p 40000:3000 \ + -e GHOST_API_KEY="${{ secrets.GHOST_API_KEY }}" \ + $IMAGE_NAME - # Warte, um sicherzustellen, dass der neue Container läuft + # Wait to ensure the new container is running sleep 10 - # Prüfe, ob der neue Container erfolgreich läuft + # Check if the new container is running successfully if [ "$(docker inspect --format='{{.State.Running}}' $NEW_CONTAINER_NAME)" == "true" ]; then - # Stoppe und entferne den alten Container, falls vorhanden + # Stop and remove the old container, if any if [ "$(docker ps -aq -f name=$CONTAINER_NAME)" ]; then docker stop "$CONTAINER_NAME" || true docker rm "$CONTAINER_NAME" || true fi - # Stoppe und entferne den temporären Container + # Stop and remove the temporary new container docker stop "$NEW_CONTAINER_NAME" || true docker rm "$NEW_CONTAINER_NAME" || true - # Starte den Container mit dem gewünschten Namen und Port - docker run -d --name "$CONTAINER_NAME" -p $PORT:3000 $IMAGE_NAME + # Start the container with the desired name and port + docker run -d --name "$CONTAINER_NAME" -p $PORT:3000 \ + -e GHOST_API_KEY="${{ secrets.GHOST_API_KEY }}" \ + $IMAGE_NAME else echo "New container failed to start." docker logs $NEW_CONTAINER_NAME exit 1 - fi \ No newline at end of file + fi diff --git a/app/api/fetchAllProjects/route.tsx b/app/api/fetchAllProjects/route.tsx index 26eb7ea..0d2f73c 100644 --- a/app/api/fetchAllProjects/route.tsx +++ b/app/api/fetchAllProjects/route.tsx @@ -3,7 +3,7 @@ import { NextResponse } from "next/server"; export const runtime = "nodejs"; // Force Node runtime const GHOST_API_URL = "http://192.168.179.31:2368"; -const GHOST_API_KEY = "067b8434f2e7f2a771dfcc45a7"; // Replace with your actual key +const GHOST_API_KEY = process.env.GHOST_API_KEY; export async function GET() { try { diff --git a/app/api/fetchProject/route.tsx b/app/api/fetchProject/route.tsx index 26d46aa..2ecb949 100644 --- a/app/api/fetchProject/route.tsx +++ b/app/api/fetchProject/route.tsx @@ -3,7 +3,7 @@ import { NextResponse } from "next/server"; export const runtime = "nodejs"; // Force Node runtime const GHOST_API_URL = "http://192.168.179.31:2368"; -const GHOST_API_KEY = "067b8434f2e7f2a771dfcc45a7"; // Replace with your actual key +const GHOST_API_KEY = process.env.GHOST_API_KEY; export async function GET(request: Request) { const { searchParams } = new URL(request.url); diff --git a/next.config.ts b/next.config.ts index e9ffa30..c18e002 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,7 +1,9 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - /* config options here */ + env: { + GHOST_API_KEY: process.env.GHOST_API_KEY, + }, }; export default nextConfig;