From dd10624ce4461cf1a858aaf2deefde463817f0da Mon Sep 17 00:00:00 2001 From: rattatwinko Date: Wed, 18 Jun 2025 16:39:43 +0200 Subject: [PATCH] WORKKKKKKKS ; Page loading works really well now. If anything goes wrong revert to this commit --- Dockerfile | 16 ++-------------- next.config.js | 3 --- pm2.config.js | 14 ++++++++++++++ src/app/api/posts/[slug]/route.ts | 2 ++ src/app/api/posts/route.ts | 2 ++ src/app/layout.tsx | 13 +++++++++++++ start_pm2.sh | 32 +++++++++++++++++++++++++++++++ 7 files changed, 65 insertions(+), 17 deletions(-) create mode 100644 pm2.config.js create mode 100755 start_pm2.sh diff --git a/Dockerfile b/Dockerfile index 7a68f18..6a3a6f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,11 @@ -# Use the official Node.js image as the base image -FROM node:14 +FROM node:20-alpine -# Set the working directory WORKDIR /app -# Copy package.json and package-lock.json COPY package*.json ./ -# Install dependencies RUN npm install -# Copy the rest of the application code COPY . . -# Build the application -RUN npm run build - -# Expose the port the app runs on -EXPOSE 8080 - -# Start the application -CMD ["npm", "start"] \ No newline at end of file +CMD ["npm", "start"] \ No newline at end of file diff --git a/next.config.js b/next.config.js index f4c1926..557b862 100644 --- a/next.config.js +++ b/next.config.js @@ -3,9 +3,6 @@ const nextConfig = { output: 'standalone', reactStrictMode: true, swcMinify: true, - server: { - port: 8080, - }, } module.exports = nextConfig \ No newline at end of file diff --git a/pm2.config.js b/pm2.config.js new file mode 100644 index 0000000..360d053 --- /dev/null +++ b/pm2.config.js @@ -0,0 +1,14 @@ +module.exports = { + apps: [ + { + name: "markdownblog-dev", + script: "npm", + args: "run dev", + watch: true, + env: { + NODE_ENV: "development", + PORT: 8080 + } + } + ] +}; \ No newline at end of file diff --git a/src/app/api/posts/[slug]/route.ts b/src/app/api/posts/[slug]/route.ts index e45cc7d..4197214 100644 --- a/src/app/api/posts/[slug]/route.ts +++ b/src/app/api/posts/[slug]/route.ts @@ -1,3 +1,5 @@ +export const dynamic = "force-dynamic"; + import { NextResponse } from 'next/server'; import fs from 'fs'; import path from 'path'; diff --git a/src/app/api/posts/route.ts b/src/app/api/posts/route.ts index 336343c..d60fc82 100644 --- a/src/app/api/posts/route.ts +++ b/src/app/api/posts/route.ts @@ -1,3 +1,5 @@ +export const dynamic = "force-dynamic"; + import { NextResponse } from 'next/server'; import fs from 'fs'; import path from 'path'; diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 427ef08..911e420 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -68,6 +68,19 @@ export default function RootLayout({ {children} + ); diff --git a/start_pm2.sh b/start_pm2.sh new file mode 100755 index 0000000..d644f1b --- /dev/null +++ b/start_pm2.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# Check the command line argument +case "$1" in + autodeploy) + echo "Starting PM2 with auto-deployment..." + pm2 start pm2.config.js + ;; + prod) + echo "Starting PM2 with production build..." + NODE_ENV=production pm2 start pm2.config.js + ;; + stop) + echo "Stopping PM2 process..." + pm2 stop all + ;; + restart) + echo "Restarting PM2 process..." + pm2 restart all + ;; + status) + echo "Showing PM2 process status..." + pm2 status + ;; + logs) + echo "Showing PM2 logs..." + pm2 logs + ;; + *) + echo "Usage: ./start_pm2 {autodeploy|prod|stop|restart|status|logs}" + ;; +esac \ No newline at end of file