Prerequisites Node.js (>= version 14) MongoDB (Make sure MongoDB is installed and running)
Clone the repository:
git clone https://github.com/gdsc-nits-org/nanolink.git
Change into the project directory:
cd nanolink
Install dependencies:
pnpm install
Create a '.env' file in the root directory and set the following environment variables:
MONGODB_URI="mongodb://johndoe:randompassword@localhost:27017/mydb"
PORT="RANDOM_PORT"
JWT_SECRET_KEY="STRONG_SECRET_KEY"
Adjust the port
and MONGODB_URI
values as needed.
- Ensure that your MongoDB server is running.
- Create a database named 'url-shortener' (or the name specified in your '.env' file).
To run tests, run the following command
pnpm run dev
- Method: POST
- Endpoint: /api/v1/signup
- Request Body:
{
"username": "example_user",
"name": "xyz",
"email": "abc@gmail.com",
"password": "password"
}
- Responses:
{
"message": "User signed up successfully"
"status": 200,
}
- Method: POST
- Endpoint: /api/v1/login
- Request Body:
{
"username": "example_user",
"password": "password"
}
- Responses:
{
"status": 200,
"msg": "Loggedin Successfully"
}
- Method: POST
- Endpoint: /api/v1/shorten
- Request Body:
{
"originalUrl": "https://example.com/very/long/url"
}
- Responses:
{
"msg": "Url shortened successfully",
"status": 200,
"shortUrl": "https://our-nanolink/abc123"
}
- Method: GET
- Endpoint: /api/v1/url/fetchAll
- Request Body:
{
"userId": "66235a95d41ea94865cc01e6"
}
- Responses:
{
"id": "66235b13d41ea94865cc01e8",
"originalUrl": "https//:google.com",
"shortUrl": "localhost/st6Wnp",
"clickedCount": 0,
"lastClicked": "Never",
"createdAt": "April 20th 2024, 11:35:07 am",
"updatedAt": "April 20th 2024, 11:35:07 am",
"userId": "66235a95d41ea94865cc01e6"
}
- Method: POST
- Endpoint: /api/v1/url/manage/shortUrl_ID
- Request Body:
{
"originalUrl": "https://example.com/very/long/url",
},
- Responses:
"msg": "Url updated successfully",
"status": 200
- Method: DELETE
- Endpoint: /api/v1/DeleteUrl/shortUrl_ID
- Responses:
{
"status": 200,
"message": "URL deleted successfully"
}
- Method: GET
- Endpoint: /api/v1/analytics/shortUrl_ID
- Responses:
{
"id": "6622da11df9bf4bfb7a347cf",
"originalUrl": "https://example.com/very/long/url",
"shortUrl": "localhost/ofib6x",
"clickedCount": 0,
"lastClicked": "Never",
"createdAt": "April 20th 2024, 2:24:40 am",
"updatedAt": "April 20th 2024, 2:24:40 am"
}
-
Purpose: Verifies the JWT token sent by the client and adds the authenticated user's information to the request object.
-
Usage: Applied to protected routes that require authentication.
Contributions are always welcome!