There are two seperate applications. The Client which serves as Frontend(using React) and the API(using Node and Express).
To run this project, you will need to add the following environment variables to your .env
file. I have provided an example file .env.example
please update it to your own in .env
file without .example
.
Variable | Description |
---|---|
MONGODB_URI |
MongoDB URI |
BASE |
Base URL for Shortening |
DOMAIN | http://localhost:3333 Or Base URL for React App |
REACT_APP_SHORT | $DOMAIN/api/short |
REACT_APP_ALL | $DOMAIN/api/all |
Clone the project
git clone https://github.com/Badhansen/url-shortener.git
Go to project directory and navigate to the api
directory.
cd url-shortener/api
Install all the dependencies
npm install
Now start the server
npm start
POST /api/short
Field | Type | Description |
---|---|---|
Body | json |
Original Url |
Example:
POST http://localhost:3333/api/short
Content-Type: application/json
{
"origUrl": "https://leetcode.com/problems/single-threaded-cpu/"
}
GET /:urlid
Parameter | Type | Description |
---|---|---|
urlid |
string |
Unique URL Code |
Example:
GET http://localhost:3333/SvPAyo
- In another terminal, navigate to the
client
directory. - Run
npm install
to install all dependencies. - Run
npm start
to start the app