Before you can run the application, ensure you have the following installed:
- PostgreSQL
- Java
- Spring Boot
- Node.js and npm
-
Start the PostgreSQL server:
- On Windows: Open the PostgreSQL app and click on "Start".
- On macOS/Linux: You can use the following command to start PostgreSQL:
sudo service postgresql start
-
Create a database named
url_shortener:- Open a PostgreSQL terminal or use a GUI like pgAdmin, and run the following SQL query:
CREATE DATABASE url_shortener;
- Open a PostgreSQL terminal or use a GUI like pgAdmin, and run the following SQL query:
-
Create the
url_mappingtable:- Run the following SQL query to create the table that will store the URL mapping:
CREATE TABLE url_mapping ( id SERIAL PRIMARY KEY, created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, original_url TEXT NOT NULL, short_url TEXT NOT NULL );
- Run the following SQL query to create the table that will store the URL mapping:
-
Grant all permissions to the user:
- You need to grant all permissions to the PostgreSQL user that your application will use to connect to the database. Run this SQL query:
GRANT ALL PRIVILEGES ON DATABASE url_shortener TO your_username;
- You need to grant all permissions to the PostgreSQL user that your application will use to connect to the database. Run this SQL query:
-
Update
application.propertiesfor backend connection:- Set the PostgreSQL username and password in the
application.propertiesfile located insrc/main/resources/.
Example:
spring.datasource.url=jdbc:postgresql://localhost:5432/url_shortener spring.datasource.username=your_username spring.datasource.password=your_password spring.jpa.hibernate.ddl-auto=update
- Set the PostgreSQL username and password in the
-
Open your terminal and navigate to the backend project directory.
-
Run the application using Maven:
mvn spring-boot:run
-
The backend should be running on
http://localhost:8080(or the port specified in theapplication.properties).
-
Open your terminal and navigate to the frontend project directory.
-
Install the required dependencies:
npm install
-
Start the frontend application:
npm start
-
The frontend should be accessible at
http://localhost:3000.
- Access the frontend at
http://localhost:3000and interact with the application. - The frontend will communicate with the backend via API requests.