Frontend and Backend setup

0

I have set the backend to listen on localhost port 8080 and the frontend on port 4300. How can I configure these parameters for a testing environment so that everyone can access the frontend and enable communication between the frontend and backend? Additionally, my backend stores data at the location:

public static final String DIRECTORY = System.getProperty("user.home") + "/Downloads/uploads/";

Can I use this configuration if I start an EC2 micro instance on AWS?

Nikola
asked 3 months ago277 views
1 Answer
0

Hello,

Please try this solution it will be resolved your Question.

Step 1: Launch an EC2 Instance

Go to the EC2 Dashboard in the AWS Management Console.

Click "Launch Instance".

Choose an Amazon Machine Image (AMI), such as Amazon Linux 2 or Ubuntu.

Select an instance type (e.g., t2.micro).

Configure the security group to allow HTTP (port 80), a custom TCP rule for port 8080, and SSH (port 22) for your IP

Step 2: Configure Security Groups

Ensure your security group has the following rules:

Type Protocol Port Range Source HTTP TCP 80 0.0.0.0/0 Customs TCP TCP 8080 0.0.0.0/0 SSH TCP 22 Your IP

Step 3: Connect to the EC2 Instance

Connect to your EC2 instance using SSH

ssh -i /path/to/your-key.pem ec2-user@your-ec2-public-ip

Step 4: Install Dependencies

Update the package lists and install necessary software

sudo apt-get update
sudo apt-get install -y openjdk-11-jdk nodejs npm

Step 5: Set Up the Backend

Deploy your backend application:

Upload your backend application to the instance or clone your repository.

Ensure your backend listens on 0.0.0.0 (or the EC2 public IP) on port 8080.

Start your backend application (replace with your actual start command)

java -jar your-backend-application.jar

Step 6: Set Up the Frontend

Deploy your frontend application:

Upload your frontend application to the instance or clone your repository.

Configure the frontend to communicate with the backend by setting the backend API URL.

Start the frontend server to listen on 0.0.0.0 on port 80 (or port 4300 if preferred)

cd /path/to/your/frontend
npm install
ng build --prod
sudo npm install -g serve
sudo serve -s dist -l 80

Step 7: Ensure Communication Between Frontend and Backend

Set the backend API URL in the frontend configuration

// src/environments/environment.ts
export const environment = {
  production: false,
  apiUrl: 'http://your-ec2-public-ip:8080'
};

EXPERT
answered 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions