From 2f9f05d6386392520e7cb10003ebce1c9a04d709 Mon Sep 17 00:00:00 2001 From: Tien-BH Date: Thu, 10 Jul 2025 11:14:07 +0700 Subject: [PATCH] Improve docker file --- .dockerignore | 3 ++ Dockerfile | 32 ++++++++++++++++++++ docker-compose.yaml | 12 ++++++++ src/app/api/customer-dependant/[id]/route.ts | 12 ++++---- 4 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..eac004e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.git +.next +node_modules \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..84f9081 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +# Stage 1: Build +FROM node:18-slim AS builder + +WORKDIR /app + +# Copy dependencies first to cache better +COPY package.json package-lock.json ./ +RUN npm install + +# Copy all source code +COPY . . + +# Build the Next.js app +RUN npm run build + + +# Stage 2: Run production image +FROM node:18-slim + +WORKDIR /app + +COPY --from=builder /app/package.json /app/package-lock.json ./ +RUN npm install --omit=dev + +COPY --from=builder /app/.next .next +COPY --from=builder /app/public public +COPY --from=builder /app/next.config.ts ./ +COPY --from=builder /app/src src + +EXPOSE 3000 + +CMD ["npx", "next", "start"] diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..0d49f64 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,12 @@ +version: "3.9" + +services: + app: + build: + context: . + dockerfile: Dockerfile + container_name: cosmos-crm + ports: + - "3000:3000" + environment: + - JWT_SECRET=8f2e9c4a7b1d6e3f8a5b2c9e6f1a4d7b8e3f6a9c2d5e8b1f4a7c0e3d6f9b2a5c8 diff --git a/src/app/api/customer-dependant/[id]/route.ts b/src/app/api/customer-dependant/[id]/route.ts index 4028154..6755ac6 100644 --- a/src/app/api/customer-dependant/[id]/route.ts +++ b/src/app/api/customer-dependant/[id]/route.ts @@ -3,14 +3,14 @@ import { db } from "@/database/database"; export async function GET( request: NextRequest, - { params }: { params: { id: string } } + { params }: { params: Promise<{ id: string }> } ) { try { // Initialize database await db.read(); // Parse dependant ID from params - const dependantId = parseInt(params.id); + const dependantId = parseInt((await params).id); if (isNaN(dependantId)) { return NextResponse.json( @@ -61,14 +61,14 @@ export async function GET( export async function PUT( request: NextRequest, - { params }: { params: { id: string } } + { params }: { params: Promise<{ id: string }> } ) { try { // Initialize database await db.read(); // Parse dependant ID from params - const dependantId = parseInt(params.id); + const dependantId = parseInt((await params).id); if (isNaN(dependantId)) { return NextResponse.json( @@ -141,14 +141,14 @@ export async function PUT( export async function DELETE( request: NextRequest, - { params }: { params: { id: string } } + { params }: { params: Promise<{ id: string }> } ) { try { // Initialize database await db.read(); // Parse dependant ID from params - const dependantId = parseInt(params.id); + const dependantId = parseInt((await params).id); if (isNaN(dependantId)) { return NextResponse.json( -- 2.49.1