diff --git a/DockerFile b/DockerFile index 2802a98..82f4240 100644 --- a/DockerFile +++ b/DockerFile @@ -1,23 +1,36 @@ -FROM node:18-alpine +# Stage 1: Build +FROM node:18-alpine AS builder WORKDIR /app -# Copy package files and install dependencies COPY package.json package-lock.json ./ -RUN npm install +RUN npm install --production -# Copy the rest of the code COPY . . -# Build Next.js +# Build-time environment variable +ARG NEXT_PUBLIC_API_URL=https://cmcbackend.rootxwire.com +ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL + RUN npm run build +# Stage 2: Run +FROM node:18-alpine AS runner + +WORKDIR /app + +COPY --from=builder /app/package.json ./ +COPY --from=builder /app/package-lock.json ./ +COPY --from=builder /app/.next ./.next +COPY --from=builder /app/public ./public +COPY --from=builder /app/next.config.js ./next.config.js + +RUN npm install --production + EXPOSE 3000 -# Make sure Next.js binds to all interfaces +ENV NODE_ENV=production +ENV NEXT_PUBLIC_API_URL=https://cmcbackend.rootxwire.com ENV HOST=0.0.0.0 -# Optionally, set the API URL here if you want -ENV NEXT_PUBLIC_API_URL=https://cmcbackend.rootxwire.com - CMD ["npm", "start"] diff --git a/docker-compose.yml b/docker-compose.yml index a95bfbf..92fd906 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,14 +2,14 @@ version: "3.9" services: nextjs: - build: . + build: + context: . + args: + NEXT_PUBLIC_API_URL: https://cmcbackend.rootxwire.com container_name: cmc_nextjs_pro ports: - "9012:3000" environment: - - NODE_ENV=production - - NEXT_PUBLIC_API_URL=https://cmcbackend.rootxwire.com + NODE_ENV: production + NEXT_PUBLIC_API_URL: https://cmcbackend.rootxwire.com restart: unless-stopped - volumes: - - .:/app - - /app/node_modules \ No newline at end of file diff --git a/src/lib/facultyData.ts b/src/lib/facultyData.ts index 531d1a5..8c38555 100644 --- a/src/lib/facultyData.ts +++ b/src/lib/facultyData.ts @@ -52,7 +52,8 @@ export interface FacultyApiResponse { // API service class export class FacultyService { - private static baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:8080'; + private static baseUrl = + process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8080'; static async getAllFaculty(): Promise { try { @@ -63,9 +64,7 @@ export class FacultyService { }, }); - if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); - } + if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`); const data: FacultyApiResponse = await response.json(); return this.transformProfessorsToTeamMembers(data.content); @@ -77,8 +76,6 @@ export class FacultyService { static async getFacultyById(id: number): Promise { try { - // Find by array index from getAllFaculty for now - // In production, you might want a direct API call const allFaculty = await this.getAllFaculty(); return allFaculty.find(member => member.id === id) || null; } catch (error) {