Before you begin, ensure you have the following installed on your machine:
Follow these steps to set up and run the application:
Clone the repository containing the application code to your local machine:
git clone git@github.com:parmeet10/url-shortner.git
cd url-shortnerPOSTGRES_CONNECTION_STRING=your_postgres_connection_string
POSTGRES_HOST=your_postgres_host
POSTGRES_PORT=your_postgres_port
POSTGRES_USER=your_postgres_user
POSTGRES_PASSWORD=your_postgres_password
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_CALLBACK_URL=your_google_callback_url
DEVELOPMENT_HOST=your_development_host
PRODUCTION_HOST=your_production_host
NODE_ENV=development # or productionuse Docker Compose to build and run the application along with the Redis service:
docker-compose up --build
This command will build the Docker image based on the Dockerfile and start both the application and Redis service
Once the application is running, you can access it at http://localhost:3000 in your web browser.
To stop the application, press CTRL + C in the terminal where you ran docker-compose up. If you need to remove the containers, run:
docker-compose down
- To view logs for the application, use:
docker-compose logs url-shortner-app-1
- To access the Redis CLI, you can run:
docker exec -it redis redis-cli
- if you encounter any issues while running the application, check the following:
- Ensure that Docker is running and that you have the necessary permissions.
- Verify your environment variable values in the .env file.
- Check the application logs for any error messages.
- constact me at sparmeet162000@gmail.com
GET /auths/providers
This endpoint retrieves a list of authentication providers available for the application.
curl --location 'http://urlshortner.kesug.com/auths/providers' \
--header 'x-device-id: 1' \
--header 'x-origin: 1' \
--header 'x-platform: 1' \
--header 'x-version: 1'{
"code": "success",
"error": false,
"message": "Successful",
"data": {
"providers": [
{
"id": 1,
"provider": "Google",
"code": "google",
"active": true
}
]
}
}{
"code": "error",
"error": true,
"message": "An error occurred while fetching providers.",
"data": null
}- 400: Bad Request - The request was invalid or improperly formatted.
- 401: Unauthorized - The request lacks valid authentication credentials.
- 500: Internal Server Error - An error occurred on the server while processing the request.
- Ensure that the required headers are included in the request.
- The
x-device-id,x-origin,x-platform, andx-versionheaders are necessary for the server to process the request correctly.
GET /auths/requests/social
This endpoint initiates a social authentication request using the specified provider ID.
- provider_id (required): The ID of the authentication provider.
- state (required): A unique string to maintain state between the request and callback.
curl --location 'http://urlshortner.kesug.com/auths/requests/social?provider_id=1&state=1234'{
"code": "success",
"error": false,
"message": "Successful",
"data": {
"user": {
"id": 2,
"email": "sparmeet162000@gmail.com",
"first_name": null,
"role": {
"id": 1,
"role": "user"
}
},
"session": {
"id": 1,
"email": "sparmeet162000@gmail.com",
"role_id": "1",
"token": "168b91c71e004a8b8fd01d2452a25137",
"user_id": "2",
"expiry": "2025-03-25T19:00:47.503Z",
"active": true,
"device_id": 1,
"identifier": "default.device",
"origin_id": "1",
"platform_id": "1",
"app_version": "1",
"user_agent": "Node.js/23.0.0 (OS X; arm64)"
}
}
}{
"code": "error",
"error": true,
"message": "An error occurred while initiating social authentication.",
"data": null
}- 400: Bad Request - The request was invalid or missing required parameters.
- 401: Unauthorized - The request lacks valid authentication credentials.
- 500: Internal Server Error - An error occurred on the server while processing the request.
- Ensure that the
provider_idandstatequery parameters are included in the request.
POST /api/shorten
This endpoint allows users to shorten a long URL.
curl --location 'http://34.68.184.28:3000/api/shorten' \
--header 'x-device-id: 1' \
--header 'x-origin: 1' \
--header 'x-platform: 1' \
--header 'x-version: 1' \
--header 'x-auth: 168b91c71e004a8b8fd01d2452a25137' \
--header 'Content-Type: application/json' \
--data '{\
"longUrl":"https://supabase.com"\
}' | Field | Type | Required | Description |
|---|---|---|---|
| longUrl | string | Yes | The long URL to be shortened. |
{
"code": "success",
"error": false,
"message": "Successful",
"data": {
"urlData": {
"short_url": "http://34.68.184.28:3000/api/shorten/1l",
"created_at": "2024-12-25T19:05:03.937Z"
}
}
}| Field | Type | Description |
|---|---|---|
| code | string | Status code of the response. |
| error | boolean | Indicates if there was an error. |
| message | string | Descriptive message about the result. |
| data | object | Contains the shortened URL data. |
| urlData | object | Details of the shortened URL. |
| short_url | string | The shortened URL. |
| created_at | string | Timestamp of when the URL was created. |
{
"code": "error",
"error": true,
"message": "An error occurred while redirection.",
"data": null
}- 400: Bad Request - The request was invalid or improperly formatted.
- 401: Unauthorized - The request lacks valid authentication credentials.
- 500: Internal Server Error - An error occurred on the server while processing the request.
- Ensure that the required headers are included in the request.
- The
x-device-id,x-origin,x-platform,x-version,x-authheaders are necessary for the server to process the request correctly.
GET api/shorten/:alias
This endpoint redirects short url to a long url saved into the sytstem
| Type | Required | Description |
|---|---|---|
| string | Yes | short url alias. |
curl --location 'http://34.68.184.28:3000/api/shorten/1l' \
--header 'x-device-id: 1' \
--header 'x-origin: 1' \
--header 'x-platform: 1' \
--header 'x-version: 1' \
--header 'x-auth: 168b91c71e004a8b8fd01d2452a25137' \
--data ''<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<!-- Further HTML content will follow -->
</head>
<body>
<!-- Redirect content -->
</body>
</html>{
"code": "error",
"error": true,
"message": "An error occurred while redirection.",
"data": null
}- 400: Bad Request - The request was invalid or improperly formatted.
- 401: Unauthorized - The request lacks valid authentication credentials.
- 500: Internal Server Error - An error occurred on the server while processing the request.
- Ensure that the required headers are included in the request.
- The
x-device-id,x-origin,x-platform,x-version,x-authheaders are necessary for the server to process the request correctly.
GET api/analytics/:alias
This endpoint provides analytics of the alias
| Type | Required | Description |
|---|---|---|
| string | Yes | short url alias. |
curl --location 'http://34.68.184.28:3000/api/analytics/1l' \
--header 'x-device-id: 1' \
--header 'x-origin: 1' \
--header 'x-platform: 1' \
--header 'x-version: 1' \
--header 'x-auth: 168b91c71e004a8b8fd01d2452a25137'{
"code": "success",
"error": false,
"message": "Successful",
"data": {
"analytics": {
"totalClicks": 9,
"uniqueClicks": 2,
"clicksByDate": [
{
"date": "2024-12-25T00:00:00.000Z",
"clicks": 9
}
],
"osType": [
{
"osType": "unknown os",
"uniqueclicks": 2,
"uniqueUsers": 1
}
],
"deviceType": [
{
"deviceType": "unknown device",
"uniqueclicks": 9,
"uniqueUsers": 1
}
]
}
}
}| Field | Type | Description |
|---|---|---|
| code | string | Status code of the response. |
| error | boolean | Indicates if there was an error. |
| message | string | Descriptive message about the result. |
| data | object | Contains the analytics data for the shortened URL. |
| analytics | object | Detailed analytics information. |
| totalClicks | number | Total number of clicks on the shortened URL. |
| uniqueClicks | number | Total number of unique clicks on the shortened URL. |
| clicksByDate | array | List of click counts grouped by date. |
| date | string | The date of the clicks in ISO 8601 format. |
| clicks | number | The number of clicks on that specific date. |
| osType | array | List of operating system types and their click statistics. |
| osType | string | The type of operating system. |
| uniqueclicks | number | Number of unique clicks from that operating system. |
| uniqueUsers | number | Number of unique users from that operating system. |
| deviceType | array | List of device types and their click statistics. |
| deviceType | string | The type of device. |
{
"code": "error",
"error": true,
"message": "An error occurred while redirection.",
"data": null
}- 400: Bad Request - The request was invalid or improperly formatted.
- 401: Unauthorized - The request lacks valid authentication credentials.
- 500: Internal Server Error - An error occurred on the server while processing the request.
- Ensure that the required headers are included in the request.
- The
x-device-id,x-origin,x-platform,x-version,x-authheaders are necessary for the server to process the request correctly.
GET api/analytics/topic/:topic
This endpoint provides analytics of the topic
| Type | Required | Description |
|---|---|---|
| string | Yes | topic. |
curl --location 'http://34.68.184.28:3000/api/analytics/topic/unknown' \
--header 'x-device-id: 1' \
--header 'x-origin: 1' \
--header 'x-platform: 1' \
--header 'x-version: 1' \
--header 'x-auth: 168b91c71e004a8b8fd01d2452a25137'{
"code": "success",
"error": false,
"message": "Successful",
"data": {
"topicAnalytics": {
"totalClicks": 9,
"uniqueClicks": 1,
"urls": [
{
"shortUrl": "http://34.68.184.28:3000/api/shorten/1l",
"totalClicks": 9,
"uniqueClicks": 1
}
]
}
}
}| Field | Type | Description |
|---|---|---|
| code | string | Status code of the response. |
| error | boolean | Indicates if there was an error. |
| message | string | Descriptive message about the result. |
| data | object | Contains the analytics data for the shortened URL. |
| topicAnalytics | object | Detailed analytics information. |
| totalClicks | number | Total number of clicks on the shortened URL. |
| uniqueClicks | number | Total number of unique clicks on the shortened URL. |
| urls | array | List of urls. |
| totalClicks | number | Total number of clicks on the shortened URL. |
| uniqueClicks | number | Total number of unique clicks on the shortened URL. |
{
"code": "error",
"error": true,
"message": "An error occurred while redirection.",
"data": null
}- 400: Bad Request - The request was invalid or improperly formatted.
- 401: Unauthorized - The request lacks valid authentication credentials.
- 500: Internal Server Error - An error occurred on the server while processing the request.
- Ensure that the required headers are included in the request.
- The
x-device-id,x-origin,x-platform,x-version,x-authheaders are necessary for the server to process the request correctly.
GET api/analytics/overall
This endpoint provides analytics of the topic
curl --location 'http://34.68.184.28:3000/api/analytics/overall' \
--header 'x-device-id: 1' \
--header 'x-origin: 1' \
--header 'x-platform: 1' \
--header 'x-version: 1' \
--header 'x-auth: 168b91c71e004a8b8fd01d2452a25137'{
"code": "success",
"error": false,
"message": "Successful",
"data": {
"overallAnalytics": {
"totalUrls": 1,
"totalClicks": 9,
"uniqueClicks": 2,
"clicksByDate": [
{
"date": "2024-12-25T00:00:00.000Z",
"clicks": 9
}
],
"osType": [
{
"osType": "unknown os",
"uniqueclicks": 2,
"uniqueUsers": 1
}
],
"deviceType": [
{
"deviceType": "unknown device",
"uniqueclicks": 9,
"uniqueUsers": 1
}
]
}
}
}| Field | Type | Description |
|---|---|---|
| code | string | Status code of the response. |
| error | boolean | Indicates if there was an error. |
| message | string | Descriptive message about the result. |
| data | object | Contains the analytics data for the shortened URL. |
| overallAnalytics | object | Detailed analytics information. |
| totalUrls | number | Total number of urls registerd by user. |
| totalClicks | number | Total number of clicks on the shortened URL. |
| uniqueClicks | number | Total number of unique clicks on the shortened URL. |
| clicksByDate | array | List of click counts grouped by date. |
| date | string | The date of the clicks in ISO 8601 format. |
| clicks | number | The number of clicks on that specific date. |
| osType | array | List of operating system types and their click statistics. |
| osType | string | The type of operating system. |
| uniqueclicks | number | Number of unique clicks from that operating system. |
| uniqueUsers | number | Number of unique users from that operating system. |
| deviceType | array | List of device types and their click statistics. |
| deviceType | string | The type of device. |
{
"code": "error",
"error": true,
"message": "An error occurred while redirection.",
"data": null
}- 400: Bad Request - The request was invalid or improperly formatted.
- 401: Unauthorized - The request lacks valid authentication credentials.
- 500: Internal Server Error - An error occurred on the server while processing the request.
- Ensure that the required headers are included in the request.
- The
x-device-id,x-origin,x-platform,x-version,x-authheaders are necessary for the server to process the request correctly.