This project is a full-stack web application for shortening URLs. It consists of a backend built with Node.js, Express, and Firebase Firestore, and a frontend built with React and TypeScript (ReactTSX).
- Overview
- Tech Stack
- Project Structure
- Getting Started
- Environment Variables
- API Endpoints
- Contributing
- License
This application allows users to create short URLs and redirect to the original URLs using the provided short codes. The backend manages the API for URL shortening and redirection, while the frontend provides a user interface for interacting with these features.
- Backend: Node.js, Express
- Database: Firebase Firestore
- Frontend: React, TypeScript, Tailwind CSS
- Environment Configuration: dotenv
project-root/
├── backend/
│ ├── .env
│ ├── index.js
│ ├── package.json
│ ├── package-lock.json
│ └── node_modules/
└── frontend/
├── public/
├── src/
│ ├── components/
│ │ ├── home.tsx
│ │ ├── nav.tsx
│ ├── App.tsx
│ ├── App.css
│ ├── index.css
├── .gitignore
├── index.html
├── package.json
├── tailwind.config.js
└── vite.config.ts
Ensure you have the following installed:
- Node.js (v14 or later)
- npm (v6 or later)
- Firebase account with Firestore set up
-
Clone the Repository:
git clone <your-repo-url> cd backend
-
Install Dependencies:
npm install
-
Configure Environment Variables:
Create a
.envfile in the root of thebackenddirectory and add the environment variables as shown in the Environment Variables section. -
Run the Backend Server:
npm start
The backend server should now be running on
http://localhost:3000.
Ensure you have the following installed:
- Node.js (v14 or later)
- npm (v6 or later)
-
Navigate to the Frontend Directory:
cd frontend -
Install Dependencies:
npm install
-
Start the Frontend Development Server:
npm run dev
The frontend should now be running on
http://localhost:5173.
The backend requires the following environment variables:
PORT=3000
# Firebase configuration
FIREBASE_TYPE=<your_firebase_type>
FIREBASE_PROJECT_ID=<your_firebase_project_id>
FIREBASE_PRIVATE_KEY_ID=<your_firebase_private_key_id>
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n<your_private_key>\n-----END PRIVATE KEY-----\n"
FIREBASE_CLIENT_EMAIL=<your_firebase_client_email>
FIREBASE_CLIENT_ID=<your_firebase_client_id>
FIREBASE_AUTH_URI=<your_firebase_auth_uri>
FIREBASE_TOKEN_URI=<your_firebase_token_uri>
FIREBASE_AUTH_PROVIDER_X509_CERT_URL=<your_firebase_auth_provider_cert_url>
FIREBASE_CLIENT_X509_CERT_URL=<your_firebase_client_cert_url>
FIREBASE_UNIVERSE_DOMAIN=<your_firebase_universe_domain>The frontend uses environment variables defined in the vite-env.d.ts file.
- Endpoint:
/shorten - Method:
POST - Request Body:
{ "longUrl": "https://www.example.com", "shortCode": "customShortCode" } - Response:
200 OK: Returns the shortened URL.400 Bad Request: MissinglongUrlorshortCode.409 Conflict: TheshortCodealready exists.500 Internal Server Error: Server error.
- Endpoint:
/:shortCode - Method:
GET - Response:
- Redirects to the original URL.
404 Not Found: Short URL not found.500 Internal Server Error: Server error.