This project is a Next.js frontend application that fetches data from a backend service and falls back to a placeholder response if the backend is unavailable. The application can be run locally or inside a Docker container. Additionally, it supports configuring the backend URL through environment variables.
Before running this project, ensure that you have the following installed:
- Node.js
- Docker
- Docker Compose (Optional for multi-container environments)
git clone https://github.com/srinathSanjeeva/nextjs-frontend.git
cd nextjs-frontend
npm install
To run the app locally with a specific backend URL, create an .env.local
file:
# .env.local
NEXT_PUBLIC_BACKEND_URL=http://your-backend-url
Now, start the development server:
npm run dev
The app will be accessible at http://localhost:3000.
To build the Docker image, run the following command:
docker build -t docker-username/nextjs-frontend .
You can run the Docker container on port 4000
and pass the backend URL as an environment variable:
docker run -p 4000:3000 -e NEXT_PUBLIC_BACKEND_URL=http://your-backend-url docker-username/nextjs-frontend
The app will be accessible at http://localhost:4000.
If you need to update the Docker image after making changes, follow these steps:
docker build -t docker-username/nextjs-frontend .
docker push docker-username/nextjs-frontend
If you want to tag the image with a new version (e.g., v2
), use:
docker build -t docker-username/nextjs-frontend:v2 .
docker push docker-username/nextjs-frontend:v2
The following environment variables can be configured:
NEXT_PUBLIC_BACKEND_URL
: The URL for the backend service. It defaults to a placeholder if not provided.
You can also manage your containers and environment variables using Docker Compose. Create a docker-compose.yml
file as shown below:
version: '3'
services:
nextjs-app:
build: .
ports:
- '4000:3000'
environment:
- NEXT_PUBLIC_BACKEND_URL=http://your-backend-url
To start the app with Docker Compose:
docker-compose up
This project is licensed under the MIT License.
Feel free to open issues or submit pull requests for any improvements.
This README.md
provides a complete guide for setting up and running the project, both locally and in Docker. Let me know if you'd like to add or modify any sections!