This is a template website for a URL Shortening built using Vite + React. The website is styled using bootstrap and uses react-router-dom to redirect to different pages. This template basically involves two text fields and 3 buttons for performing the basic functioning of a URL Shortening website.
The main motive of building this template is to create a website to send request to backend which will processes the request of URL Shortening service. The URL for the backend service can be given in and evnironment file and the connection can be established. This given template is used for a Spring boot application for the backend.
- console output for errors, requests, etc. are availble for debugging
- webpage is made responsive using
bootstrap .envfile for setting up connection with backend securelydockerfilefor create a container image of the wesite- TODO : home page, about, and others based on preference
- submit, clear, copy buttons for user friendly experience
- textinput configured for valid URLs only
npmfor running and building the projectgitfor cloning the repositorydockerfor creating container images of the website [optional]
Clone the repository using git
git clone https://github.com/pratham-ak2004/URL-StoreNavigate to the root directory
cd URL-StoreInstall the node modules form package.json using npm. You can download the LTS version of npm form Node
npm installCreate .env file of your own referring .env.example file and add the URL's for your ACTIVE front-end and back-end host
VITE_ACTIVE_SERVER = "" ## change appropriately
VITE_ACTIVE_PAGE = "" ## change appropriatelyRun the development sever to see the results
npm run devTo build the project use the below command. This will produce a folder named dist which can be used for hosting
npm run build
npm run preview ## To preview your buildThere may be several errors or problems while running this project. Below are some solutions to the errors
Error Generate.jsx:23 POST http://localhost:8080/generate/addUrl net::ERR_CONNECTION_REFUSED
Solution The following error can be seen when your site is not getting conneted with the backend. You can try the following solutions.
- Check you evironment variable
VITE_ACTIVE_SERVER. It must be the root URL where your backend is running e.g. http://localhost:8080 if your back-end is hosted locally - Change the POST mapping URL in
Generate.jsxat line:23
await fetch(`${import.meta.env.VITE_ACTIVE_SERVER}/generate/addUrl`, { //tobe configured
}Error Shortened URL is not being redirected
Solution The following error can me solved by:
- Configuring the environment variable
VITE_ACTIVE_PAGE. It must me the root URL where the current project is running e.g. http://localhost:5173 if your front-end is hosted locally in development server - Change display and redirect URL in the following files:
line:70 ofGenerate.jsxline:12 ofurlToDisplay = `${import.meta.env.VITE_ACTIVE_PAGE}/` + url.shortUrl; //tobe configured
Redirect.jsxwindow.location.href = `${import.meta.env.VITE_ACTIVE_SERVER}/redirect/${target}`; //tobe configured
Feel free to contact me : )
