This is a project that consists of a front-end built with React.js, a back-end built with FastAPI, and a MySQL database.
To get started with this project, follow these steps:
Before you can run the front-end and back-end servers, you need to have the following software installed on your machine:
- Node.js
- npm
- Python 3
- pip
- MySQL
To install the project dependencies, run the following command in URL_Shortener/frontend/url-shortener/
:
npm install
This will install all the necessary dependencies for the front-end server.
To install the back-end dependencies, run the following command in URL_Shortener/backend/
:
pip install -r requirements.txt
This will install all the necessary dependencies for the back-end server.
Before you can start the servers, you need to set the API URL and port in the .env
file. Follow these steps to set up the API URL and port:
-
Open the
.env
file in theURL_Shortener/frontend/url-shortener/
directory. -
Update the
REACT_APP_API_URL
andREACT_APP_API_PORT
fields with the correct API URL and port. For example:
REACT_APP_API_URL=127.0.0.1
REACT_APP_API_PORT=8000
Replace 127.0.0.1
with the IP address or domain name of your server, and 8000
with the port number that the back-end server will be running on.
To set up the database, follow these steps:
- Run the following command to start up the MySQL server:
mysqld.exe --console
-
Log in to MySQL using the command line or a MySQL client.
-
Create a new database for the URL Shortener application:
CREATE DATABASE url_shortener;
- Import the
data.sql
file to create the necessary tables and data:
USE url_shortener;
SOURCE URL_Shortener/backend/data.sql;
This will create the necessary tables and data for the application.
Before you can start the back-end server, you need to set up the database connection in database.py
. Follow these steps to set up the database connection:
-
Open the
database.py
file in theURL_Shortener/backend/
directory. -
Update the
SQLALCHEMY_DATABASE_URL
field with the correct database connection information. For example:
SQLALCHEMY_DATABASE_URL = "mysql+pymysql://root:<password>@localhost:3306/url_mapping_db"
Replace <password>
with the password for the root user.
- Save the database.py file.
To start the front-end server, run the following command in URL_Shortener/frontend/url-shortener/
of the project:
npm start
This will start the front-end server on port 3000.
To start the back-end server, run the following command in URL_Shortener/backend/
:
uvicorn main:app --host 0.0.0.0 --reload
This will start the back-end server on port 8000.
Once the servers are running, you can access the application by opening a web browser and navigating to http://localhost:3000. This will display the front-end of the application.
The back-end API can be accessed by sending HTTP requests to http://localhost:8000. The API documentation can be found in the http://localhost:8000/docs.
- React.js
- FastAPI
- MySQL
- Oscar Ng
This project is licensed under the MIT License - see the LICENSE file for details.