task manager
visit https://dipakgiri.tech login credentials
for normal user:
email: user@user.com
password: User1@user.com
for admin user:
email: admin@admin.com
password: Admin1@admin.com
This guide provides instructions for setting up and running the project locally, testing the backend, and deploying the application on a server. The project includes a Vite React frontend and a Node.js backend managed through Docker.
- Requirements
- Local Setup
- Running Backend Tests
- Deployment Guide for Server
- Environment Variables
- Troubleshooting
- Docker: Required to containerize and run the application.
- Docker Compose: Manages the multi-container setup.
- Git: For cloning the repository.
- Node.js and npm: Required for local development and running tests.
To run the project locally using Docker:
-
Clone the Repository
git clone https://github.com/DipakTech/task-app.git cd task-app
-
Set Up Environment Variables
-
Create
.env
files in both thefrontend
andbackend
directories with the following dummy values:For Backend (
backend/.env
):PORT=4000 NODE_ENV=production ACCESS_TOKEN_SECRET=myaccesstokensecret POSTGRES_URL="postgres://user:password@localhost:5432/mydatabase" POSTGRES_PRISMA_URL="postgres://user:password@localhost:5432/mydatabase" POSTGRES_URL_NO_SSL="postgres://user:password@localhost:5432/mydatabase" POSTGRES_URL_NON_POOLING="postgres://user:password@localhost:5432/mydatabase" POSTGRES_USER="user" POSTGRES_HOST="localhost" POSTGRES_PASSWORD="password" POSTGRES_DATABASE="mydatabase"
For Frontend (
frontend/.env
):VITE_BASE_URL="http://localhost:4000/api/" VITE_API_KEY=sampleapikey
-
-
Build and Start Containers Run the following command from the project root:
docker-compose up --build -d
-
Access the Application
- Frontend: http://localhost:3000
- Backend API: http://localhost:4000/api
Note: The
docker-compose.yml
file handles container networking, so the frontend will automatically connect to the backend API.
To run backend tests locally:
-
Install Dependencies (If not using Docker):
cd backend npm install
-
Run Tests
- Use the following command to run the test suite defined in the
package.json
:This runs Jest tests based on the configuration innpm test
jest.config.cjs
.
- Use the following command to run the test suite defined in the
-
Additional Test Commands:
- Run tests with a custom Jest configuration:
npx jest --config jest.config.js
- For development testing with TypeScript:
npm run dev
- Run tests with a custom Jest configuration:
Note: Ensure that environment variables required for tests are set up in
.env
or use a test-specific.env.test
file if needed.
The deploy.sh
script will automate the deployment process on a server, including installing Docker, Docker Compose, and Nginx, as well as setting up environment variables.
-
Upload or Access the Server:
- Upload
deploy.sh
to the server or log in via SSH.
- Upload
-
Run the Deployment Script
sudo bash deploy.sh
The script performs the following:
- Installs Docker and Docker Compose (if not already installed).
- Configures Nginx as a reverse proxy for backend and frontend, with rate limiting.
- Clones the GitHub repository if not already present.
- Sets up swap memory to improve server performance.
- Creates environment files for both frontend and backend.
- Builds and launches Docker containers.
- Configures Nginx to start on boot and manages traffic.
-
Access the Application
- The application will be available at
http://your-domain.com
(replace with your server’s domain).
- The application will be available at
Below are the main environment variables used in the .env
files:
Variable | Description | Example Value |
---|---|---|
PORT |
Port for the backend server | 4000 |
NODE_ENV |
Node environment (e.g., production) | production |
ACCESS_TOKEN_SECRET |
Token secret for authentication | myaccesstokensecret |
POSTGRES_URL |
Primary database connection URL | postgres://user:password@localhost:5432/mydatabase |
VITE_BASE_URL |
Base URL for API in the frontend | http://localhost:4000/api/ |
VITE_API_KEY |
API key for frontend | sampleapikey |
Replace dummy values with actual secrets and URLs as necessary for production.
-
Check Container Status:
docker-compose ps
-
View Logs:
- Nginx Logs:
sudo journalctl -u nginx
- Docker Logs:
docker-compose logs
- Nginx Logs:
For any configuration changes, repeat the steps for updating environment variables and restart the containers.
This guide provides step-by-step instructions for running and deploying the application, including backend testing. For additional help, refer to the logs in the troubleshooting section.